JS form Verification

Source: Internet
Author: User

Lists some common format-validated JS methods for querying.

//Check if it is a numberfunctionCheckisinteger (str) {if(str = = ""){         return false; }        if(Str.search (/^[0-9]+$/) < 0){         return false; }        Else{         return true; }}//Check if integerfunctionChecknum (str) {if(!str | |IsNaN (str)) {         return false; } STR= (STR * 1). toString (); if(Str.indexof (".") = =-1){         return false; }        return true;}//Check whether the password is valid, the password is only allowed to be made up of ASCII, this function is only used when modifying or registering a passwordfunctioncheckvalidpasswd (str) {varReg =/^[x00-x7f]+$/; if(!reg.test (str)) {         return false; }        if(Str.length < 6 | | str.length > 16){         return false; }        return true;}//Check whether it is ChinesefunctionIschn (str) {varReg =/^[u4e00-u9fa5]+$/; if(!reg.test (str)) {         return false; }        return true;}//Check if it is a valid real name and can only contain Chinese or uppercase English lettersfunctionIsvalidtruename (strName) {varstr = Trim (strName);//determines whether it is a full English capital or full Chinese, and can contain spaces        varReg =/^[a-z u4e00-u9fa5]+$/; if(Reg.test (str)) {return false; }        return true;}//Check MailboxfunctionIsemail (str) {varreg =/^ ([a-za-z0-9_-]) [email protected] ([a-za-z0-9_-]) + ((\.[ a-za-z0-9_-]{2,3}) $/; returnreg.test (str);}//Check Phone numberfunctionIstel (str) {varreg=/^ ([0-9]|[ \-])+$/G; if(Str.length<7 | | str.length>18){         return false; }        Else{          returnreg.exec (str); }}//Check Agefunctionisage (str) {varMydate=NewDate; varnow=mydate.getfullyear (); if(Str < now-60 | | | str > NOW-18){         return false; }        return true;}//is a valid date format: Yyyy-mm-ddfunctionIsdateformat (TXT) {if(txt==NULL|| TXT = = "") {return false;} Else{         varRegex =/[0-9]{1,4}-[0-9]{1,2}-[0-9]{1,2}/; if(regex.test (TXT)) {varNoarr = Txt.split ("-"); varYear = eval (noarr[0]); varmonth = eval (noarr[1]); varDay = eval (noarr[2]); if(Year < 1 | | Month < 1 | | month > * | | Day < 1 | | Day > 31) {return false;} if(Month = = 4 | | month = = 6 | | month = = 9 | | month = = one) && Day > 30) {return false;} if(Month = = 2){           if(Year% 4 = 0) && Day > 29) {return false;} if(year% 4 = = 0){            if(Year% = = 0 && year%!! = 0 && Day > 29) {return false;} Else if(Day > 28){             return false; }           }          }          return false; }         Else{          return true; }        }}//detects 15-bit or 18-bit ID numbersfunctionisidcardnum (TXT) {if(txt = =NULL|| TXT = = ""){         return false; }        varIdno =txt.tostring (); varLen =idno.length; varreg; varNoarr; varDatestr= ""; if(len! = && Len! = 18){         return false; }        Else if(len = = 15) {reg=/(\d{3}) (\d{3}) (\d{2}) (\d{2}) (\d{2}) (\d{3})/; if(Reg.test (idno) = =false){          return false; }         Else{Noarr=reg.exec (IDNO); Datestr= "+noarr[3]+"-"+noarr[4]+"-"+noarr[5]; returnIsdateformat (DATESTR); }        }        Else{reg=/(\d{1}) (\d{1}) (\d{1) (\d{1}) (\d{1}) (\d{1}) (\d{1}) (\d{1}) (\d{1}) (\d{1}) (\d{1}) (\d{1}) (\d{1}) (\d{1}) {1}) (\d{1}) ([0-9xx]{1})/; if(Reg.test (idno) = =false){          return false; }         Else{Noarr=reg.exec (IDNO); Datestr= noarr[7]+noarr[8]+noarr[9]+noarr[10]+ "/" +noarr[11]+noarr[12]+ "/" +noarr[13]+noarr[14]; if(IsNaN (NewDate (datestr)) = =false){           varWI =NewArray (0,7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2); varAMT = 0; vari; varChkno =NewArray ("1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2");  for(i=1;i<18;i++) {Amt+ = (noarr[i]*Wi[i]); }           return(chkno[amt%) = = Noarr[18].touppercase ()); }          Else{           return false; }         }        }}

JS form Verification

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.