List of Useful Regular Expressions
If you need to check whether a person has entered a phone number or something else correctly, you can use regular expressions.
Last updated
If you need to check whether a person has entered a phone number or something else correctly, you can use regular expressions.
Last updated
Regular expressions are a condition by which a bot can check the format of the input data (for example, that a person has entered a phone number instead of something else)
For comparison by regular expression, the type of comparison should be put "Regular expression".
Regular expressions are written into condition, not variables for comparison!
When collecting data, the user often enters not what he is asked to enter. I will provide a typical scheme to check the correctness of the input of the phone number. In case the user has not entered the phone number, the bot will ask him to repeat the input.
From the block asking for the phone number there are 2 connections. One without the condition, and the second with the condition of regular expression of the Russian phone number: (( +7|7|8)+([0-9]){10})$ A connection to a condition just adds it to the application and will work only when the correct phone number is encountered. The second connection will work in all other cases because it has a lower priority. On the second connection, the user will be told that he entered incorrect data, and will send back to enter the phone number.
Enter only numbers: [1-9]+[0-9]*$
Credit card number: [0-9]{13.16}
ICQ: ([1-9])+(?:-? d) {4,}
Phone number ( +)? (( d{2.3}) ? d| d)((([ -]? d)|( ?( d{2.3})?)){5.12} d$
Name+First name or full name [A-YA-YAYUA-ZA-Z]+ [A-YAYA-YAYUA-ZA-Z]+ ? [A-YAYA-YAYUA-ZA-Z]+$
Set of letters and numbers (Latin): [a-zA-Z0-9]+$
Set of letters and numbers (Latin + Cyrillic): [A-YA-YAYUA-Z0-9]+$
Domain (for example abcd.com): ([a-zA-Z0-9]([a-zA-Z0-9 -]{0.61}[a-zA-Z0-9])? .)+[a-zA-Z]{2.6}$
URL (for example abcd.com): (https?): (((//)|( ))[ w:#@%/;$()~? + -= . &]*
IPv4: (25[0-5]|2[0-4] d|[01]? d?) .){3}(25[0-5]|2[0-4] d|[01]? d?)
IPv6: (( |:)([0-9a-fA-F]{0.4})){1.8}$
User name (with a limit of 2-20 characters, which can be letters and numbers, the first character is required letter): [a-zA-Z][a-zA-Z0-9- . ]{1.20}$
Password (Lowercase and uppercase Latin letters, numbers): (?=.* d)(?=.[a-z])(?=.[A-Z])(?!.* s). *
Password (Lowercase and uppercase Latin letters, numbers, special characters. Minimum 8 characters): (?= .{8,}$) (((?=.* d)|(?=.* W+))(?!![. n])(?=.[A-Z])(?=.[a-z]). *$
Date in YYYY-MM-DD format: [0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01]) UPD. Stricter check: (19|20) d-((0[1-9]|1[012])-(0[1-9]|[12] d)|(0[13-9]|1[012])-30|(0[13578]|1[02])-31)
Date in DD/MM/YYYY format: (0[1-9]|[12][0-9]|3[01]) - /.- /- . d Date in DD.MM.YYYY format: (0?[1-9]|[12][0-9]|3[01]).(0?[1-9]|1[012]). ((19|20) d)
Integers and floating-point numbers (dot delimiter): -? d+( . d{0,})?
UUID: [0-9A-Fa-f]{8} -[0-9A-Fa-f]{4} -[0-9A-Fa-f]{4-[0-9A-Fa-f]{12}
Latitude or longitude: -? d{1.3} . d+UPD. E-mail: [- w. ]+@([A-z0-9][-A-z0-9]+ .)[A-z]{2.4}$
UPD. URL in Latin. If you need to recognize and Cyrillic domains, it is necessary to change all «a-z0-9» to «a-yayoa-z0-9» and add to the list of domain zones «Russian»: ~^(?:(?:https?|ftp|telnet):/(?:[a-z0-9_-]{1.32}(?::[a-z0-9_-]{1.32})?)? (??(?:[[a-z0-9-]{1.128} .)+(?:ru|su|com|net|org|mil|edu|arpa|gov||info|aero||aero|||||aero|name|[a-z]{2})|(!0.]?????? $~i
UPD. Time in HH:MM:SS format: ([0-1] d|2[0-3])(:[0-5] d) {2}$
UPD. Mac address: ([0-9a-fA-F]{2}([:-]|$)){6}$|([0-9a-fA-F]{4}([.]|$)){3}
There are a lot of regular expressions, if you do not find the right ones in this list, you should consult the search engines.
Testing regular expressions is convenient on the site: https:/regex101.com/