Commonly used inspection code

zhaozj2021-02-16  133

When we write FORM, if you write inspection code every time, it is too low efficiency. Here there is some common inspection code, sharing with you.

/ / -------------------------------------------------------------------------------------------- ---- Space Judgment Function IsWhitespace (S) {var white = "/ t / n / r"; var i; for (i = 0; i = 0) {return true;}}

Return false;}

/ / -------------------------------------------------------------------------------------------- - Inspection character (restricted characters that cannot be entered) Function ischar (s) {var errorchar; var badchar = "> <, [] {}? / = | // '/" :; ~! @ # $% ^ & () `";

IF (s == ") {alert (" Please enter content! ") Return False;}

IF (iswhitespace (s)) {alert ("Input fleemers can not contain space characters, please re-enter!"); return false;} errorchar = ischarsinbagex (s, badchar) if (ErrorChar! = ") {Alert "The character" s "you entered is invalid, / n / n Do not enter" ErrorChar "in characters!"); Return False;}

Return True;}

/ / -------------------------------------------------------------------------------------------- --- Email's format judgment Function ISEMAIL (S) {if (ISempty (S)) {Alert ("The input E-mail address cannot be empty, please enter!"); Return false;} // is s Contain Whitespaceif (IsWhitespace (s)) {alert ("Input E-mail address cannot contain space characters, please re-enter!"); return false;} var i = 1; var len = s.ley;

IF (len> 40) {alert ("E-mail address length can not exceed 40!"); return false;}

POS1 = S.Indexof ("@"); POS2 = S.Indexof ("."); POS3 = S.lastIndexof ("@"); POS4 = S.lastIndexof ("."); if ((((POS1 <= 0) || (POS1 == LEN) || (POS2 <= 0) || (POS2 == LEN)) {Alert ("Please enter a valid E-mail address!"); Return false;} else {ix ((POS1 == POS2 - 1) || (POS1 == POS2 1) || (POS1! = POS3) // Find TWO @ || (POS4

/ / -------------------------------------------------------------------------------------------- - Digital judgment function isnum (s) {if (ISEMPTY (S)) {Alert ("must enter a number") Return False;} if (! Ischarsinbag (s, "0123456789")) {Alert ("Please check you Whether the input is a number! "); Return false;} // if (S <1) {// alert (" The number input is greater than 0! "); // Return False; ///} // if (s > 2000) {// alert ("The number of inputs is less than 2000!"); // Return False; //} return true;

/ / -------------------------------------------------------------------------------------------- - ID card judgment function iscardNum (s) {if (ISEMPTY (S)) {Alert ("must enter a number") Return False;} if (! Ischarsinbag (s, "0123456789")) {Alert ("Please check Are you entered? Quot;); return false;} if (s.Length == 15 || s.length == 18) {return true;} else {Alert ("The number of input numbers is 15 or 18-bit! "); Return false;}}

/ / -------------------------------------------------------------------------------------------- - ID card judgment (Compared with birthday month) Function isidcardNo (NUM) {if (ISNAN (NUM)) {Alert ("Input is not a number!"); Return false;} var gs = Num.length, RE ; If (len == 15) Re = new regexp (/ ^ (/ d {6}) ()? (/ D {2}) (/ d {2}) (/ d {2}) (/ d { 3}) $ /); ELSE IF (len == 18) RE = new regexp (/ ^ (/ d {6}) ()? (/ D {4}) (/ d {2}) (/ d { 2}) (/ d {3}) (/ d) $ /); Else {Alert ("Enter the number of digits!"); Return False;} var A = Num.match (re); if (a ! = null) {if (len == 15) {var d = new date ("19" a [3] "/" a [4] "/" a [5]); var b = D.Getyear () == a [3] && (D.getMonth () 1) == a [4] && D.getdate () == a [5];} else {var d = new date (a [ 3] "/" a [4] "/" a [5]); var b = d.Getfullyear () == a [3] && (d.getMonth () 1) == a [ 4] && D.getdate () == a [5];} if (! B) {alert ("Enter ID" A [0] "Birthday!"); Return False;}} Return True;} // ----------------------------------- --------------- Strict verification of ID card