Regular expressions for validating common data types
For checking text fields for validity, regular expressions are usually used. There are several of the most common types of data, such as a credit card number, a date in a specific format, etc. The html5pattern.com website collects a collection of regular expressions for such data (there it is positioned as possible content of the html5 pattern attribute of inpit elements , but these regular expressions can be used for familiar validation with javascript). Examples relevant to the Russian audience, along with the corresponding regular expressions, you can look under the cut.
Credit Card Number: [0-9] {13,16}
ICQ: ([1-9]) + (?: -? \ D) {4,}
A set of letters and numbers (Latin): ^ [a-zA-Z0-9] + $
A set of letters and numbers (Latin + Cyrillic): ^ [aaaa-yayoa-zA-Z0-9] + $
IPv4: (corrected runcore ) ((25 [0-5] | 2 [0-4] \ d | [01]? \ D \ d?) \.) {3} (25 [0-5] | 2 [0-4] \ d | [01]? \ D \ d?)
IPv6: ((^ |:) ([0-9a-fA-F] {0.4})) {1.8} $
Username (with a limit of 2-20 characters, which can be letters and numbers, the first character is necessarily a letter): ^ [a-zA-Z] [a-zA-Z0-9 -_ \.] {1.20} $
UPD .URL in Latin. If you need to recognize and Cyrillic domains, you need to change all the "a-z0-9" to "a-Yaaa-z0-9" and add to the list of domain zones " RF " (from kvf77 ): ~ ^ (?: (?: https? | ftp | telnet): // (?: [a-z0-9_-] {1.32} (? :: [a-z0-9_-] {1.32 })? @)?)? (?: (?: [a-z0-9 -] {1,128} \.) + (?: en | su | com | net | org | mil | edu | arpa | gov | biz | info | aero | inc | name | [az] {2}) | (?! 0) (? :( ?! ?! 0 [^.] | 255) [0-9] {1,3} \.) {3} (?! 0 | 255) [0-9] {1,3}) (?: / [A-z0-9., _ @% &? + = \ ~ / -] *)? (? : # [^ '\ "&] *)? $ ~ i
UPD .Time in HH: MM: SS format (from runcore ): ^ ([0-1] \ d | 2 [0-3]) (: [0-5] \ d) {2} $
Unspecified, but important in your opinion data types, you can lay out in the comments (along with regular expressions). You can also share them with html5pattern.com by filling out the form on the main page.