Telebot Python. How does the user allow only numbers?



  • I can't find information on how to allow the user to enter only numbers. int(message.text) makes a mistake. I should be grateful to those who decide to help.



  • You can't influence the user input. But you can check that he put the number on a method. isdigit or write a processor for purely chips.

    Example:

    @bot.message_handler(regexp=r"\d+")
    

    Example:

    text = '256'
    print(text.isdigit())  # True
    

    text = 'Hello, World!'
    print(text.isdigit()) # False




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2