K
K
k0smos2020-09-18 12:10:49
PHP
k0smos, 2020-09-18 12:10:49

How to create input mask (format) for tg bot in php?

Hello! Faced the problem of filtering the data sent to the tg bot. In the bot, you need to fill out a questionnaire, all data is sent to the database .. for example, with the price range field, I decided using if,elseand >,<,==. But this method does not fit all fields, for example, the date input field, you need to accept dates only in the format 10/10/2020, if the input format does not match, it should give an error

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2020-09-18
@k0smos

Regex (\d{2}\.\d{2}\.\d{4})
(two digits + dot)+(two digits + dot)+(4 digits)
An example of finding such a date in your own text:

<?php
$re = '/(\d{2}\.\d{2}\.\d{4})/m';
$str = 'только в формате 10.10.2020, если формат ввода не совпадает, должно выдать ошибку';

preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);

// Print the entire match result
var_dump($matches);

You can play with regex here: https://regex101.com/r/jZpgjB/1/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question