Regular expression Validation:
e-mail, Social Security number, postcode, telephone, mobile phone number
Mailbox:
1. Has and can only contain one @.
[email protected] at least one of the following.
3. Cannot begin with @ and. Cannot end with them.
[email protected] and. Must have at least one character.
5. If there are multiple. Words, they cannot be together.
Steps to validate with regular expressions:
1. Write the regular expression.
2. Take the value of the string to validate.
3. Use the match () method of the string to determine whether the string satisfies the regular expression.
var reg =/^ (\d{15}|\d{18}) $/; Regular expressions
var email = "370111199203059087";
if (Email.match (reg) = = null)
{
Alert ("Wrong ID format");
}
Else
{
Alert ("The identity card format is correct");
}
Qualifier for regular Expressions:--can read regular expressions.
1. Regular expressions are not quoted, but instead are used//.
2.^--the beginning of the match. $--matches the end.
3.\d-Match a number
4.\w-Match a letter or number
5.{m,n}-repeats the previous expression at least m times, repeating up to n times.
6.{m,}-repeats the previous expression at least m times, up to an unlimited number.
7.{M}-Repeats the previous expression m times
8.[8,5,2]-This position can only have one of the 8,5,2. 8,5,2 number of values and number of their own choice.
9.[0-9]-equivalent to \d
10.[A-Z,A-Z,0-9] equivalent to \w
11.+ equivalent to {1,}
12.* equivalent to {0,}
13. Equivalent to {0,1}
14. Priority ()
15. Escape \.
Simplified mailbox: \w+[@]\w+ ([.] \w+) {A}
Postcode: [1-9]\d{5}
ID number: [1-9]\d{16}[0-9,x]
Phone Number: (\d{3,4}[-]|\ (\d{3,4}\))? \d{7,8}
0533-3113118 (0533) 3113118010-23456789
20150424 Regular Expressions