Jquery Form Validation

Source: Internet
Author: User
Tags jquery form validation

Mobile phone number Verification

// Verify that the 11-digit phone number 1 starts function Checkmobile (str) {    var re =/^1\d{10}$/    if  (Re.test (str)) {          Returntrue;     Else {        returnfalse;    }};
Mobile phone number verification

/** *function  checkphone (str    ) {var re =/^0\d{2,3}-?\d{7,8}$/ ;     if (Re.test (str)) {        returntrue;     Else {        returnfalse;    }};
Phone number Verification

//Check the ID number 18 andfunctionCheckidcard (num) {console.info (num); Num=num.tolocaleuppercase ();    Console.info (num); //The ID number is 15 or 18 bits, 15 digits are all digits, 18 bits is the first 17 digits, the last one is the check digit, possibly the number or the character X.     if(! (/(^\d{15}$) | (^\d{17} ([0-9]| X) $)/. Test (num))) {        return false; }    //The check digit is generated according to ISO 7064:1983.mod 11-2, and X can be considered the number 10.     //The birth date and check digit are analyzed separately below    varLen, re; Len=num.length; if(len = = 15) {Re=NewRegExp (/^ (\d{6}) (\d{2}) (\d{2}) (\d{2}) (\d{3}) $/); varArrsplit =Num.match (re); //Check that the birthday date is correct        varDtmbirth =NewDate (' + ' + arrsplit[2] + '/' + arrsplit[3] + '/' + arrsplit[4]); varBgoodday; Bgoodday= (Dtmbirth.getyear () = = number (arrsplit[2)) && ((Dtmbirth.getmonth () + 1) = = number (arrsplit[3)) && (d Tmbirth.getdate () = = Number (arrsplit[4])); if(!bgoodday) {            return false; }        Else {            //turn 15-bit IDs into 18-bit            //The check digit is generated according to ISO 7064:1983.mod 11-2, and X can be considered the number 10.             varArrint =NewArray (7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); varArrch =NewArray (' 1 ', ' 0 ', ' X ', ' 9 ', ' 8 ', ' 7 ', ' 6 ', ' 5 ', ' 4 ', ' 3 ', ' 2 '); varntemp = 0, I; Num= Num.substr (0, 6) + ' + ' + num.substr (6, num.length-6);  for(i = 0; i < i++;) {ntemp+ = Num.substr (i, 1) *Arrint[i]; } num+ = arrch[ntemp% 11]; return true; }    }    if(len = = 18) {Re=NewRegExp (/^ (\d{6}) (\d{4}) (\d{2) (\d{2}) (\d{3}) ([0-9]| X) $/); varArrsplit =Num.match (re); //Check that the birthday date is correct        varDtmbirth =NewDate (Arrsplit[2] + "/" + arrsplit[3] + "/" + arrsplit[4]); varBgoodday; Bgoodday= (Dtmbirth.getfullyear () = = number (arrsplit[2)) && ((Dtmbirth.getmonth () + 1) = = number (Arrsplit[3])) && Amp (dtmbirth.getdate () = = Number (arrsplit[4])); if(!bgoodday) {            return false; }        Else {            //Verify that the check code for the 18-digit ID is correct.             //The check digit is generated according to ISO 7064:1983.mod 11-2, and X can be considered the number 10.             varValnum; varArrint =NewArray (7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); varArrch =NewArray (' 1 ', ' 0 ', ' X ', ' 9 ', ' 8 ', ' 7 ', ' 6 ', ' 5 ', ' 4 ', ' 3 ', ' 2 '); varntemp = 0, I;  for(i = 0; i < i++;) {ntemp+ = Num.substr (i, 1) *Arrint[i]; } valnum= arrch[ntemp% 11]; if(Valnum! = Num.substr (17, 1)) {                return false; }            return true; }    }    return false;};
Identification Number Verification

function Checkemail (str) {    var re =/^ (\w-*\.*) [email protected] (\w-?) + (\.\w{2,}) +$/    if  (Re.test (str)) {        returntrue;     Else  {        $. Zebra_dialog (' <strong> e-mail number format is incorrect </strong> ');         return false ;    }};
Mailbox Format Validation

/*Test Digital Shaping*//*Num: Characters that are subject to validation*//*Stralert: Error message*//*nummin: Numeric Minimum range (-1 means no minimum value)*//*Nummax: Maximum range of values (1 indicates unlimited maximum)*/functionchecknumint (num, Stralert, nummin, Nummax) {if($.trim (num) = = "") {        $. Zebra_dialog (' <strong> ' + Stralert + ' cannot be empty! </strong> '); return false; }    if(IsNaN (num)) {$. Zebra_dialog (' <strong> ' + Stralert + ' need to enter a number type! </strong> '); return false; } Else {        if(parseint (nummin)! =-1) {            if(num) < parseintparseint (nummin)) {                $. Zebra_dialog (The value of ' <strong> ' + Stralert + ' cannot be less than ' + Nummin + '! </strong> '); return false; }        }        if(parseint (nummax)! =-1) {            if(num) > parseintparseint (Nummax)) {                $. Zebra_dialog (The value of ' <strong> ' + Stralert + ' cannot be greater than ' + Nummax + '! </strong> '); return false; }        }        return true; }};
Digital Shaping Verification

where $. Zebra_dialog ("); For externally referenced cue controls, use alert ('); replace

functionChecknumdecimal (value, numlength) {if($.trim (value) = = "") {        $. Zebra_dialog (' <strong> ' + Stralert + ' cannot be empty! </strong> '); return false; }    if(!IsNaN (value)) {        $. Zebra_dialog (' <strong> ' + Stralert + ' need to enter decimal type! </strong> '); return false; }    if(Value! =NULL&& Value! = ") {        varDecimalindex = Value.indexof ('. ')); if(Decimalindex = = '-1 ')) {            return true; } Else {            varDecimalpart = value.substring (Decimalindex + 1); if(Decimalpart.length >parseint (numlength)) {                $. Zebra_dialog (' <strong> ' + Stralert + ' can enter up to bit ' + numlength + ' decimals! </strong> '); return false; } Else {                return true; }        }    }    return false;};
Decimal Verification

/*make sure to include a reference to Zebra_dialog in the sibling page before use*//*input detection for type input label (without checkbox)*//*Domname: The name of the DOM node*//*Stralert: Error message*//*DOM node Data length (-1 for unlimited data length)*/functioncheckinput (Domname, Stralert, numlength) {varPattern =NewREGEXP ("[~ ' [email protected]#$%^&* ()-+_=:]");//check for illegal characters    varstrvalue = $.trim ($ (' input[name= ' + domname + ') '). Val ()); if(strvalue = = "") {        $. Zebra_dialog (' <strong> ' + Stralert + ' cannot be empty! </strong> '); $(' Input[name= ' + domname + '] '). focus (); return false; } Else {        if(Pattern.test (strvalue)) {$. Zebra_dialog (' <strong> ' + Stralert + ' contains illegal characters, please check! </strong> '); $(' Input[name= ' + domname + '] '). focus (); return false; } Else {            if(parseint (numlength)! =-1) {                if(Strvalue.length <parseint (numlength)) {                    $. Zebra_dialog (' <strong> ' + Stralert + ' has a length of at least ' + numlength + ' bit, please check your input! </strong> '); $(' Input[name= ' + domname + '] '). focus (); return false; } Else {                    return true; }            } Else {                return true; }        }    }};
self-built input[name=domname] type validation type

Jquery Form Validation

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.