Common regular expression, phone number, landline number, ID number, etc.

Phone number regular expression to validate

function checkPhone () { 
     var Phone = document.getElementById ( 'Phone' ) .Value;
     IF (! (/ ^. 1 [34578] \ {D}. 9 $ / .test (Phone))) { 
        Alert ( "phone number has in error, please re-fill " );  
         return  false ; 
    } 
}

or it could be

function checkPhone () { 
     var Phone = document.getElementById ( 'Phone' ) .Value;
     IF ! ((/ ^. 1 (. 3 |. 4 |. 5 |. 7 |. 8) \ {D}. 9 $ / .test (Phone)) ) { 
        Alert ( "phone number is incorrect, please re-fill" );  
         return  to false ; 
    } 
}

Note: Parentheses as a whole is in parentheses, brackets match is one of the brackets

Regular inside the brackets [] can match only one of them, if you want to match specific sets of strings, then it must use parentheses () plus or |, I thought I could use or in parentheses | symbol, original | in parentheses is also a character, it does not represent or. [3457] Match 3 or 4 or 5 or 7, and (3457) 3457 match only, or may be added to the same with the front (3 | 4 | 5 | 7). [34 | 57] matches or 3 or 4 | 5 or 7, or the (34 | 57) can match 34 or 57.

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 is incorrect, please re-fill' );
        return  to false ; 
   } 
}

ID check

// ID regular expression (15) 
isIDCard1 = / ^ [1-9] \ D}. 7 {((0 \ D) | (. 1 [0-2])) (([0 |. 1 | 2] \ D) |. 3 [0-1]) \ {D} $. 3 / ;
 // ID regular expression (18) 
isIDCard2 = / ^ [1-9] \ {D}. 5 [1-9] \ . 3} {D ((0 \ D) | (. 1 [0-2])) (([0 |. 1 | 2] \ D) |. 3 [0-1]) \. 4 {D} $ / ; 
ID the combined regular :( ^ \ D {15} $) | (^ \. 17} {D ([0-9] | X-) $)
Network link information extraction: (h | H) (r | R) (e | E) (f | F) * = * ( '| ") (\ w | \\ | \ / | \.) +? ( '| " ? | * |>) 
to extract e-mail address information: \ w + ([- + .] \ w +) * @ \ w + ([-.] \ w +) * \ \ w + (. [-.] \ w +) * 
extracts image link information: (S | S) (R & lt | R & lt) (C | C) * = * ( '| ") (\ W | \\ | \ / | \) + (?. ? '| "| * |> ) 
extracts the IP address information: (\ d +) \ (\ d +) \ (\ d +) \ (\ d +... ) 
extract information in Chinese telephone number (including mobile and fixed phone): (\ (\ D { ? 3,4-} \) | \ D {3,4-} - | \ S) \ D {7,14 } 
extract information in China ZIP: [ 1-9] { }. 1 (\ + D). 5 { } 
extract information China ID number: \ D { 18 is} | \ D {15 } 
to extract an integer of information: \ D + 
extract information in floating-point (i.e. decimals) :( ? - \ d *) \ \ d +.? 
extract any digital information :( - \ d *) (\ \ d +)?.? 
extract information in Chinese string: [\ u4e00 - \ u9fa5] * 
extract information the double-byte character string (characters): [ ^ \ x00- \ xFF] *

Usage: test () method to find whether there is in the string specified regular expression and returns a Boolean value and returns true if it exists, otherwise false.

Guess you like

Origin www.cnblogs.com/gopark/p/10966319.html