A regular expression (regular expression) is an object that describes the character pattern. JavaScript regular expressions can be used for powerful pattern matching and text retrieval and substitution functions.
Cell phone number Regular expression validation.
function Checkphone () {
var phone = document.getElementById (' phone '). Value;
if (!) ( /^1[3|4|5|7|8]\d{9}$/.test (phone)) {
alert ("Mobile phone number is wrong, please refill");
return false;
}
}
Here's a quick explanation:
^1[3|4|5|7|8]\d{9}$
The expression begins with 1, and the second may be any of the 3/4/5/7/8, with the following \d representing the 9 digits of the number [0-9], combined with a total of 11 digits.
Please refer to this article to explain: JS Latest mobile phone number test regular expression (absolutely can let you understand)
I guess you might like the article about JavaScript Regular: Regular expressions in regular JavaScript summary (lots of regular) JavaScript regular expressions (examples)
Fixed phone number Regular expression:
function Checktel () {
var tel = document.getElementById (' tel '). Value;
if (!/^ (\d{3,4}\) |\d{3,4}-|\s) \d{7,14}$/.test (tel)) {
alert (' Fixed telephone error, please refill ');
return false;
}
}
ID Card:
Identity card Regular expression (15-bit)
isidcard1=/^[1-9]\d{7} ((0\d) | ( 1[0-2])) (([0|1|2]\d) |3[0-1]) \d{3}$/;
Identity card Regular expression (18-bit)
isidcard2=/^[1-9]\d{5}[1-9]\d{3} ((0\d) | ( 1[0-2])) (([0|1|2]\d) |3[0-1]) \d{4}$/;
Identity card consolidation: (^\d{15}$) | (^\d{17} ([0-9]| X) $)
Latest phone number Regular expression: January 2016 13 Update, the following is no longer used
var tel = $ ("#telNo"). Val (); Get mobile number
var Telreg =!! Tel.match (/^ (0|86|17951)? ( 13[0-9]|15[012356789]|17[678]|18[0-9]|14[57]) [0-9]{8}$/);
If the phone number cannot pass the Verify if
(Telreg = = False) {
}
2015-11-20 (new compatible phone and mobile phone)
((\d{11}) |^ ((\d{7,8}) | ( \D{4}|\D{3})-(\d{7,8}) | (\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}) | (\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}) $)
Match format:
11-digit Mobile phone number
3-4-bit area code, 7-8-digit live number, 1-4 non-transposition machine number
such as: 12345678901, 1234-12345678-1234
Use the same way as above:
var Telreg =!! Tel.match (/^ (\d{11}) |^ ((\d{7,8}) | ( \D{4}|\D{3})-(\d{7,8}) | (\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}) | (\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})) $ $/);
If you pass the authentication if
(Telreg) {
}
Other
The code from http://caibaojian.com/regexp-example.html
extracts the network links in the information: (h| H) (r| R) (e| E) (f| F) *= * (' | ')? (\w|\\|\/|\.) +('|"| *|>)?
Message address in the extraction information: \w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) *
extract the picture link in the information: (s| S) (r| R) (c| C) *= * (' | ')? (\w|\\|\/|\.) +('|"| *|>)?
Extract the IP address in the information: (\d+) \. (\d+) \. (\d+) \. (\d+)
The Chinese mobile number in the Extract information: (*0*13\d{9) The
Chinese fixed telephone number in the extraction information: (\d{3,4}\) |\d{3,4}-|\s? \d{8}
Extract the Chinese phone number in the information (including mobile and fixed telephone):(\ ( \d{3,4}\) |\d{3,4}-|\s? \d{7,14}
Extract information from china ZIP code: [1-9]{1} (\d+) {5}
extract the Chinese identity card number in the information: \d{18}|\d{15}
Extract the Integer in the information: \d+
The floating-point number (that is, the decimal number) in the extraction information: (-?\d*) \.? \d+
Extract any number in the information: (-?\d*) (\.\d+)?
Extract the Chinese string in the information: [\u4e00-\u9fa5]*
extract the Double byte string in the message (Kanji): [^\x00-\xff]*
Use:
The test () method finds in the string whether a specified regular expression exists, returns a Boolean value, returns True if it exists, or returns false.
var pattern = new RegExp (' Box ', ' I ');
var str = ' box ';
Alert (Pattern.test (str)); True
var pattern =/box/i;
var str = ' box ';
Alert (Pattern.test (str)); True
var pattern =/box/i;
var str = ' is a box ';
Alert (Pattern.test (str)); True
Original link: JS latest mobile phone number, phone number regular expression of copyright, reprint, please specify the source, offenders must investigate.
Annotated source format: Front-End development blog (http://caibaojian.com/regexp-example.html)