Useful RegEx patterns
Hi Friends,
Today I am not writing something about the SharePoint, but this will be more useful for the client side development. So in many scenarios we need to validate the input string eg valid email address and more.
I have found some of the common used validations which we can validate using the regular expressions. I'll be adding more to these as I encounter more and feel free to let me know if you need any more.
Today I am not writing something about the SharePoint, but this will be more useful for the client side development. So in many scenarios we need to validate the input string eg valid email address and more.
I have found some of the common used validations which we can validate using the regular expressions. I'll be adding more to these as I encounter more and feel free to let me know if you need any more.
Title | Description | Regular Expression |
---|---|---|
Date Time Format | Regular expression will match the dates with dashes or slashes or spaces. eg: dd-mm-yyy or dd/mm/yyy and optional time separated by space or dash eg: dd-mm-yyy-hh:mm:ss | /^(0?[1-9]|[12][0-9]|3[01])([ \/\-])(0?[1-9]|1[012])\2([0-9][0-9][0-9][0-9])(([ -])([0-1]?[0-9]|2[0-3]):[0-5]?[0-9]:[0-5]?[0-9])?$/ |
24 hour time format | Regular expression to matches time in 24 hour format | /^([01]?[0-9]|2[0-3]):[0-5][0-9]$/ |
ISO 8601 format for Date and Time | Regular expression will match the valid ISO-8601 date and time format | /^(?![+-]?\d{4,5}-?(?:\d{2}|W\d{2})T)(?:|(\d{4}|[+-]\d{5})-?(?:|(0\d|1[0-2])(?:|-?([0-2]\d|3[0-1]))|([0-2]\d{2}|3[0-5]\d|36[0-6])|W([0-4]\d|5[0-3])(?:|-?([1-7])))(?:(?!\d)|T(?=\d)))(?:|([01]\d|2[0-4])(?:|:?([0-5]\d)(?:|:?([0-5]\d)(?:|\.(\d{3})))(?:|[zZ]|([+-](?:[01]\d|2[0-4]))(?:|:?([0-5]\d)))))$/ |
HTML tags | Regular expression to match opening and closing HTML tags with content between | /^<([a-z1-6]+)([^<]+)*(?:>(.*)<\/\1>| *\/>)$/ |
Happy Validating
- Sumit Kanchan
Comments
Post a Comment