Sunday, December 13, 2015

Regular expressions

Username:
/^[a-z0-9_-]{3,16}$/

 Password:
/^[a-z0-9_-]{6,18}$/

 Matchign an email:
/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/

 Matching a phone numeber:
^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}$
123-456-7890
(123) 456-7890
123 456 7890
123.456.7890
+91 (123) 456-7890

 IP address
/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/