Thursday, 26 February 2015

Regular Expression to validate input text

Regular expression for Alpha numeric:

^[0-9a-zA-Z]+$


Regular expression for Alpha numeric with space:

^[0-9a-zA-Z ]+$


Regular expression for Alpha numeric with length:

^[0-9a-zA-Z]{5,} +$


Regular expression for Alpha numeric with single Quote and dot:

^[0-9a-zA-Z'.]+$

Regular expression for Email:

\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*

Regular expression for For contact:

^[01]?[- .]?(\([2-9]\d{2}\)|[2-9]\d{2})[- .]?\d{3}[- .]?\d{4}$

There are different format for Phone number. To Validate following:


  • (123) 456 7899
  • (123).456.7899
  • (123)-456-7899
  • 123-456-7899
  • 123 456 7899
  • 1234567899
use following expression:
'\(?([0-9]{3})\)?([ .-]?)([0-9]{3})\2([0-9]{4})'

No comments:

Post a Comment