Answer the question
In order to leave comments, you need to log in
How to validate user input?
I welcome everyone! Please tell me how to do user input validation through SQLite database. It is necessary that the user enters a number that is in the database in a certain line and certain actions are performed. Let me show you a code example:
def onetwofre(message):
try:
line_number = message.text
check = cursor.execute('SELECT * FROM Table_table WHERE line_number=?', (line_number, )).fetchone()
if (message.text.isdigit()) and : # Вот тут застрял, какое условие необходимо поставить?
bot.send_message(message.chat.id, 'Именно этот номер и нужен, вы отправили число, которое есть в таблице')
if (message.text.isdigit()) and (check is None):
bot.send_message(message.chat.id, 'Вы отправили число, которого нет в таблице')
else:
bot.send_message(message.chat.id, 'Вы отправили что угодно, но не число.')
except Exception as e:
bot.send_message(message.chat.id, 'Ошибка')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question