Simple verification of JS parameters

Source: Internet
Author: User

 var verification={    //Verify time Format 8:00  vtime: function  (s)  {      var ar = s.split (': '), flag = true;       if  (ar.length != 2)  FLAG = false;       else {          if  ( !/^[\d]+$/.test (ar[0])  | |  !/^[\d]+$/.test (ar[1])  FLAG = false;           else {              if   (parseint (ar[0])  < 0 | |  parseint (ar[0])  > 23 | |  parseint (ar[1])  < 0 | |  parseint (ar[1])  > 59)  FLAG = false;           }      }           return flag;  },  //determines whether the character entered is an integer        isInteger:function  (str) {                  if (str.length!=0) {                 var    reg=/^[-+]?\d*$/;                     Return  reg.test (str);          }       },        //verify phone   isphone : function  (str) {                 if (str.length!=0) {                var  reg=/^((\d2,3) | (\d{3}\-))? (0\d2,3|0\d{2,3}-)? [1-9]\d{6,7} (\-\d{1,4})?$/;                return reg.test (str);         }      },  //Verification URL  isUrl:function  (str) {                if (str.length!=0) {               var  reg=/^http:\/\/[a-za-z0-9]+\. [a-za-z0-9]+[\/=\?%\ -&_~ ' @[\]\ ': +!] * ([^<>\ "\"]) *$/  ;                return reg.test (str);           }      },  //determine if the input ZIP code (only six-bit) is correct      iszip:function   (str) {&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSp;if (str.length!=0) {              var  reg=/^\d{6}$/;              return  reg.test (str);         }       } ,   //determine if the email format entered is correct       isEmail:function  ( STR)  {             if (str.length!=0) {               var   reg=/ ^\w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) *$/;              return  Reg.test (str);          }      },     //Verifying longitude   isLon:function  (str) {&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSp;       if (str.length!=0) {               var  reg=/^-? (?:(? : 180 (?: \. 0{1,5})?) | (?:(?:(? : 1[0-7]\d) | (?: [1-9]?\d)] (?:\. \d{1,5})) $/;              return reg.test ( STR);         }      },   Verify latitude   isLat:function  (str) {              if (str.length!=0) {               var reg=/^-? ((0|\d| [1-8]\d|] (\.\d{1,7})? | 90 (\.0{1,7})?)? $/;              return reg.test ( STR);          }      },   //Verify special character   isalllegal:function  (str) {     var reg = /^[^@\/\ ' \\\ "#$%&\^\*]+$/;     return reg.test (str);    },  //Verify that the first 5 characters are Chinese characters, verify the name of the hospital entered, or long text   isStartChinese:function  (str) {    var s=str.substr (0, 5);          var reg=/^[\u0391-\uFFE5]+$/;           return reg.test (str);    },     //determines whether the character entered is Chinese       isChinese:function  (str) {               if (str.length!=0) {               var   reg=/^[\u0391-\uFFE5]+$/;               return reg.test (str);           }      }    }; 

JS various parameters simple validation

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.