Tuesday, April 28, 2015

Regular expression in JavaScript

In JavaScript regular expressions are object. Regular expressions are patterns used to match character combinations in strings.

Example 1
i for case-insensitive search


Example 2


Example 3
^ indicates the beginning of the string. Using a ^ meta character requires that the match start at the beginning.
\d indicates a digit character and the {5} following it means that there must be 5 consecutive digit characters.
$ indicates the end of the string. Using a $ meta character requires that the match end at the end of the string.


Example 4


Example 5


Example 6


Example 7
Matches end of input.
For example, /t$/ does not match the 't' in "eater", but does match it in "eat"


Example 8


Example 9


Example 10
The \w meta character is used to find a word character.
A word character is a character from a-z, A-Z, 0-9, including the _ (underscore) character.


Example 11
validation password
password can contain digits
password can contain character lower or upper case
password must have length between 5 to 10
password can contain _ (underscore)


Example 12
validation password
password can contain digits
password can contain character lower or upper case
password must have length between 5 to 15
password can contain !@#$%^&*_ (special character)


Example 13
validation password
password should contain atleast one digit
password should contain atleast one special character
password can contain character lower or upper case
password must have length between 5 to 15


Example 14
validation password
password should contain atleast one digit
password should contain atleast one special character
password should contain atleast one upper case latter
password can contain character lower or upper case
password must have length between 5 to 15


Example 15
validation
atleast one number
atleast one lower case latter
atleast one upper case latter
must have more than 5 length

No comments:

Post a Comment