JavaScript IP, domain name, mobile number Regular expression validation code _ regular Expression

Source: Internet
Author: User
Tags zip domain name validation
This cell phone number is the correct validation function can be said to be the latest support, which has a detailed description, no matter what the next increase in the number of sections we are very easy to modify a little bit.
JavaScript phone number Regular expression validation function

Copy Code code as follows:

IP and domain name validation functions
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 ("Not the correct domain name");
Document.ipform.ip.focus ();
return false;
}
}
else{
Iparray = Ip.split (".");
j = Iparray.length
if (j!=4)
{
Alert ("Not the correct IP");
Document.ipform.ip.focus ();
return false;
}

for (Var i=0;i<4;i++)
{
if (iparray[i].length==0 | | iparray[i]>255)
{
Alert ("Not the correct IP");
Document.ipform.ip.focus ();
return false;
}
}
}
}
Cell 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 ("Not a full 11-digit cell phone number or the correct number of the top seven");
Document.mobileform.mobile.focus ();
return false;
}
}
Zip Code validation function
function Checkzip () {
var szip = Document.zipform.zip.value
if (!) ( /^\d{4,6}$/.test (Szip))) {
Alert ("Please 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 ("Please enter a 3-7-bit area code that starts 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 ("Please enter 15-or 18-digit ID number");
Document. IDform.userid.focus ();
return false;
}

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.