In this section, I will be writing some REGEX that could be helpful to your projects.
REGEX #1: Numbers Separated by comma or blank spaces.Example(1,2 ,3 ,4)
//Numbers Separated by comma or blank spaces
^[\d]{1,}(\s*,\s*[\d]{1,})+$
REGEX #2: Only number
//Only Number
^(\d)+$
REGEX #3: Alphanumeric
//Only Alphanumeric
^(\w)+$
REGEX #4: Validate URL (either http, https or IP number)
//Validate URL (either htpp,https or IP number)
^(http|https):\/\/([\w+?\.\w+])+([a-zA-Z0-9\~\!\@\#\$\%\^\&\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)?$
REGEX #5: Validate Emails. Example : myUser.test01@gmail.com
//Validate emails
^[\w_.+-]+@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$
REGEX #6: Validate Hours format
//Validate Hours Format
^[\d]{1,2}:[\d]{1,2}:[\d]{1,2}$
REGEX #7: Validate date format
//Validate date Format
^[\d]{2}\/[\d]{2}\/[\d]{4}$
REGEX #8: Validate IP number format (IPV4)
//Validate IP number format (IPV4)
^[\d]{1,3}.[\d]{1,3}.[\d]{1,3}.[\d]{1,3}$
REGEX #9: Regular expression to limit number of characters to 10
//Limit number of characters to 10
^[a-zA-Z]{1,10}$
REGEX #10: Regular expression: Match Not equal to the string "login"
//Match Not Equal to the string "login"
^(?!login$).+$
No comments:
Post a Comment