Provides several useful JavaScript validation scripts

Source: Internet
Author: User
Tags format object return
javascript| Script

Here are a few useful JavaScript validation scripts, the following is a code snippet for your reference.

       
        
function Isnum (num,low,hi) {if isNaN (num) | | num<low| |  Num>hi) return false; return true;}  function Isvalidip (v) {nums=v.split (".");  if (nums.length!=4) return false;  for (j=0;j<4;j++) {if (!isnum (nums[j],0,255)) return false; return true;}    function Checkip (object,desc,maybeempty) {var strvalue= object.value;      if (maybeempty) {if (Strvalue.length ==0) {return true;    } if (Isvalidip (strvalue) ==false) {alert (Desc + "Format error!");    Object.focus ();  return false; return true;}  function Checkport (object,desc,lowest,maybeempty) {var pattern=/^\d{4,5}$/;      var strvalue= object.value;      if (maybeempty) {if (Strvalue.length ==0) {return true;    } if (Strvalue.match (pattern) = = null) {alert (Desc + "Format error!");    Object.focus ();  return false;      } if (Strvalue<lowest | | strvalue >65535) {alert (Desc + "Format error!");      Object.focus ();  return false; return true;} function checkfitlongsTR (object,desc,maybeempty) {var pattern=/^\s{0,25}$/;    var strvalue= object.value;      if (maybeempty) {if (Strvalue.length ==0) {return true;    } if (Strvalue.match (pattern) = = null) {alert (Desc + "Format error!");    Object.focus ();  return false; return true;}  function Checkfitlongnum (object,desc,maybeempty) {var pattern=/^\d{0,8}$/;    var strvalue= object.value;      if (maybeempty) {if (Strvalue.length ==0) {return true;    } if (Strvalue.match (pattern) = = null) {alert (Desc + "Format error!");    Object.focus ();  return false; return true;}  function CHECKGC (object,desc) {var pattern =/^\-{0,1}\d{1,2}$/var strvalue = Object.value;  if (Strvalue.length ==0) {return true;    } if (Strvalue.match (pattern) = = null) {alert (Desc + "Format error!");    Object.focus ();  return false; } if (strvalue <-12 | |    strvalue >) {alert (Desc + "Format error!");    Object.focus ();  return false; return true;}
       


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.