This phone number Regular Expression verification function can be said to be supported by the latest version, which has detailed descriptions. No matter what number segment is added in the future, it is very easy to slightly modify it.
Javascript mobile phone number Regular Expression verification function
CopyCode The Code is as follows: // ip address and domain name verification function
Function checkip ()
{
VaR iparray, IP, J;
IP = Document. ipform. IP. value;
If (/[A-Za-Z _-]/. Test (IP )){
If (IP. indexof ("")> = 0 ){
IP = IP. Replace (// G ,"");
Document. ipform. IP. value = IP;
}
If (IP. tolowercase (). indexof ("http: //") = 0 ){
IP = IP. Slice (7 );
Document. ipform. IP. value = IP;
}
If (! /^ ([\ W-] + \.) + (COM) | (net) | (org) | (Gov \. CN) | (Info) | (CC) | (com \. CN) | (net \. CN) | (Org \. CN) | (name) | (BIZ) | (TV) | (CN) | (MoBi) | (name) | (SH) | (AC) | (IO) | (TW) | (com \. tw) | (HK) | (com \. HK) | (WS) | (travel) | (US) | (TM) | (LA) | (me \. UK) | (Org \. UK) | (LTD \. UK) | (PLC \. UK) | (in) | (EU) | (IT) | (JP) $ /. test (IP )){
Alert ("Incorrect domain name ");
Document. ipform. IP. Focus ();
Return false;
}
}
Else {
Iparray = IP. Split (".");
J = iparray. Length
If (J! = 4)
{
Alert ("Incorrect IP Address ");
Document. ipform. IP. Focus ();
Return false;
}
For (VAR I = 0; I <4; I ++)
{
If (iparray [I]. Length = 0 | iparray [I]> 255)
{
Alert ("Incorrect IP Address ");
Document. ipform. IP. Focus ();
Return false;
}
}
}
}
// Mobile phone number verification function
Function checkmobile (){
VaR smobile = Document. mobileform. Mobile. Value
If (! (/^ 1 [3 | 4 | 5 | 8] [0-9] \ D {4, 8} $/. Test (smobile ))){
Alert ("the first seven digits of a complete 11-digit mobile phone number or a correct mobile phone number ");
Document. mobileform. Mobile. Focus ();
Return false;
}
}
// Postal code verification function
Function checkzip (){
VaR szip = document.zipform.zip. Value
If (! (/^ \ D {4, 6 }$/. Test (szip ))){
Alert ("Enter the first 4-6 digits of the zip code ");
Return false;
}
}
// Area code verification
Function checkzone (){
VaR szone = Document. zoneform. Zone. Value
If (! (/^ 0 \ D {2, 6} $/. Test (szone ))){
Alert ("enter a 3-7 area code starting with" 0 ");
Return false;
}
}
// ID card verification
Function checkid (){
VaR SID = Document. idform. userid. Value
If (! (/^ \ D {15 }$ | ^ \ D {18 }$ | ^ \ D {17} [XX] $/. Test (SID ))){
Alert ("enter a 15-digit or 18-digit ID card number ");
Document. idform. userid. Focus ();
Return false;
}