ip138 a variety of client-side validation JS Code _ Regular Expression

Source: Internet
Author: User

Copy Code code as follows:

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

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;
}
window.open (', ' Mobilewindow ', ' height=197,width=350,status=yes,toolbar=no,menubar=no,location=no ')
}

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;
}
window.open (', ' Searchwindow ', ' Height=197,width=400,status=yes,toolbar=no,menubar=no,location=no,resizable=yes , Scrollbars=yes ')
}

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;
}
window.open (', ' Searchwindow ', ' Height=197,width=400,status=yes,toolbar=no,menubar=no,location=no,resizable=yes , Scrollbars=yes ')
}

function Checkarea2zip () {
var Sarea = Document.area2zipForm.area.value
if (sarea== "") {
Alert ("Please enter Address");
Document.area2zipForm.area.focus ();
return false;
}
if (sarea.length<2) {
Alert ("Address must have at least 2 words");
Document.area2zipForm.area.focus ();
return false;
}
window.open (', ' Searchwindow ', ' Height=197,width=400,status=yes,toolbar=no,menubar=no,location=no,resizable=yes , Scrollbars=yes ')
}

function Checkarea2zone () {
var Sarea = Document.area2zoneForm.area.value
if (sarea== "") {
Alert ("Please enter Address");
Document.area2zoneForm.area.focus ();
return false;
}
if (sarea.length<2) {
Alert ("Address must have at least 2 words");
Document.area2zoneForm.area.focus ();
return false;
}
window.open (', ' Searchwindow ', ' Height=197,width=400,status=yes,toolbar=no,menubar=no,location=no,resizable=yes , Scrollbars=yes ')
}

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

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.