How to validate Input type using Regular Expression

validate using regular expression

Senior Developer Asked on January 23, 2017 in JAVASCRIPT.
Add Comment
1 Answer(s)

Three letter country code validation

input type=”text” name=”country_code” pattern=”[A-Za-z]{3}” title=”Three letter country code”

Email address validation

^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$

Date validation[yyyy-mm-dd]

^(19|20)dd[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$

Regular Expression Description
[abc] Any character between the brackets
[^abc] Any character not between the brackets
[0-9] Any digit between the brackets
[^0-9] Any digit not between the brackets
(x|y) Any of the alternatives specified
[a-z] Any character from lowercase a to z
[A-Z] Any character from lowercase A to Z
[^a-zA-Z] Any string not containing any of the characters ranging from a-z and A-Z.
^.{2}$  It matches any string containing exactly two characters.
Team Leader Answered on March 19, 2017.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.