Regular Expression verification code for JavaScript IP, domain name, and mobile phone number

Source: Internet
Author: User

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;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.