Javascript several commonly used form input judgement

Related Tags:

  / / Function: chksafe 
  / / Function description: check whether they contain "'",' \ \',"/" 
  / / Parameter Description: It is necessary to check the string 
  / / Return values: 0: 1: No 

  Function chksafe (a) 
  ( 
  Return 1; 
  / * Fibdn = new Array ( " '", "\ \", "", "", ";" "/"); 
  I = fibdn.length; 
  J = a.length; 
  For (ii = 0; ii <i, ii) 
  (For (jj = 0; jj <j; jj) 
  Temp1 = (a.charAt (jj); 
  Temp2 = fibdn [ii]; 
  If (tem '; p1 == temp2) 
  (Return 0;) 
  ) 
  ) 
  Return 1; 
  * / 
  ) 

  / / Function: chkspc 
  / / Function description: check if they contain spaces 
  / / Parameter Description: It is necessary to check the string 
  / / Return values: 0: 1: No 

  Function chkspc (a) 
  ( 
  Var i = a.length; 
  Var j = 0; 
  Var k = 0; 
  While (k <i) 
  ( 
  If (a.charAt (k)! = "") 
  J j = 1; 
  K = k 1; 
  ) 
  If (j == 0) 
  ( 
  Return 0; 
  ) 

  If (i! = J) 
  2 (return;) 
  Else 
  ( 
  Return 1; 
  ) 
  ) 

  / / Function: chkemail 
  / / Function description: check whether Email Address 
  / / Parameter Description: It is necessary to check the string 
  / / Return values: 0: No. 1: 

  Function chkemail (a) 
  (Var i = a.length; 
  Var temp = a.indexOf ('@'); 
  Var tempd = a.indexOf ('.'); 
  If (temp> 1) ( 
  If ((i-temp)> 3) ( 

  If ((i-tempd)> 0) ( 
  Return 1; 
  ) 

  ) 
  ) 
  Return 0; 
  ) / / Opt1 negative decimal opt2 
  / / 1:00 when opt2 to check whether the negative num 
  / / 1:00 when opt1 to check whether the minority num 
  / / 1 is right, wrong is 0 
  Function chknbr (num, opt1, opt2) 
  ( 
  Var i = num.length; 
  Var staus; 
  / / Staus for the record. Number of 
  Status = 0; 
  If ((opt2! = 1) & (num.charAt (0 )=='-')) 
  ( 
  / / Alert ( "You have enter a invalid number."); 
  Return 0; 

  ) 
  / / When the last one was. Error 
  If (num.charAt (i-1 )=='.') 
  ( 
  / / Alert ( "You have enter a invalid number."); 
  Return 0; 
  ) 

  For (j = 0; j <i; j) 
  ( 
  If (num.charAt (j )=='.') 
  ( 
  Status; 
  ) 
  If (status> 1) 
  ( 
  / / Alert ( "You have enter a invalid number."); 
  Return 0; 
  ) 
  If (num.charAt (j) <0 '| | num.charAt (j)>'9') 
  ( 
  If (((opt1 == 0) | | (num.charAt (j )!='.')) & & (j! = 0)) 
  ( 
  / / Alert ( "You have enter a invalid number."); 
  Return 0; 
  ) 
  ) 
  ) 
  Return 1; 
  ) 
  / / Function: chkdate 
  / / Function description: check whether the date 
  / / Parameter Description: It is necessary to check the string 
  / / Return values: 0: No Date 1: Yes Date 



  Function chkdate (datestr) 
  ( 
  Var lthdatestr 
  If (datestr! = "") 
  Lthdatestr = datestr.length; 
  Else 
  Lthdatestr = 0; 

  Var tmpy = ""; 
  Var tmpm = ""; 
  Var tmpd = ""; 
  / / Var datestr; 
  Var status; 
  Status = 0; 
  If (lthdatestr == 0) 
  Return 0 


  For (i = 0; i <lthdatestr; i) 
  (If (datestr.charAt (i) == '-') 
  ( 
  Status; 
  ) 
  If (status> 2) 
  ( 
  / / Alert ( "Invalid format of date!"); 
  Return 0; 
  ) 
  If ((status == 0) & & (datestr.charAt (i )!='-')) 
  ( 
  Tmpy = tmpy datestr.charAt (i) 
  ) 
  If ((status == 1) & (datestr.charAt (i )!='-')) 
  ( 
  Tmpm = tmpm datestr.charAt (i) 
  ) 
  If ((status == 2) & & (datestr.charAt (i )!='-')) 
  ( 
  Tmpd = tmpd datestr.charAt (i) 
  ) 

  ) 
  Year = new String (tmpy); 
  Month = new String (tmpm); 
  Day = new String (tmpd) 
  / / Tempdate = new String (year month day); 
  / / Alert (tempdate); 
  If ((tmpy.length! = 4) | | (tmpm.length> 2) | | (tmpd.length> 2)) 
  ( 
  / / Alert ( "Invalid format of date!"); 
  Return 0; 
  ) 
  If (! ((1 <= month) & & (12> = month) & & (31> = day) & & (1 <= day))) 
  ( 
  / / Alert ( "Invalid month or day!"); 
  Return 0; 
  ) 
  If (! ((Year% 4) == 0) & & (month == 2) & & (day == 29)) 
  ( 
  / / Alert ( "This is not a leap year!"); 
  Return 0; 
  ) 
  If ((month <= 7) & & ((month% 2) == 0) & & (day> = 31)) 
  ( 
  / / Alert ( "This month is a small month!"); 
  Return 0; 

  ) 
  If ((month> = 8) & & ((month% 2) == 1) & (day> = 31)) 
  ( 
  / / Alert ( "This month is a small month!"); 
  Return 0; 
  ) 
  If ((month == 2) & & (day == 30)) 
  ( 
  / / Alert ( "The Febryary never has this day!"); 
  Return 0; 
  ) 

  Return 1; 
  ) 
  / / Function: fucPWDchk 
  / / Function description: check if they contain non-numeric or alphanumeric 
  / / Parameter Description: It is necessary to check the string 
  / / Return values: 0: containing 1: All numeric or alphanumeric 


  Function fucPWDchk (str) 
  ( 
  Var strSource = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
  Var ch; 
  Var i; 
  Var temp; 

  For (i = 0; i <= (str.length-1) i) 
  ( 

  Ch = str.charAt (i); 
  Temp = strSource.indexOf (ch); 
  If (temp ==- 1) 
  ( 
  Return 0; 
  ) 
  ) 
  If (strSource.indexOf (ch) ==- 1) 
  ( 
  Return 0; 
  ) 
  Else 
  ( 
  Return 1; 
  ) 
  ) 

  Function jtrim (str) 
  (While (str.charAt (0) == "") 
  Str.substr str = ((1);) 
  While (str.charAt (str.length-1) == "") 
  (Str.substr str = (0, str.length-1);) 
  Return (str); 
  ) 

  / / Function: fucCheckNUM 
  / / Function description: check whether the figures 
  / / Parameter Description: It is necessary to check the figures 
  / / Return value: 1 for the figures, the number 0 is not 

  Function fucCheckNUM (NUM) 
  ( 
  Var i, j, strTemp; 
  StrTemp = "0123456789"; 
  If (NUM.length == 0) 
  Return 0 
  For (i = 0; i <NUM.length; i) 
  ( 
  J = strTemp.indexOf (NUM.charAt (i)); 
  If (j ==- 1) 
  ( 
  / / Note characters are not just numbers 
  Return 0; 
  ) 
  ) 
  / / Note figures 
  Return 1; 
  ) 
  / / Function: fucCheckTEL 
  / / Function description: check whether the numbers 
  / / Parameter Description: It is necessary to check the string 
  / / Return value: 1 for a lawful, not for legitimate 0 

  Function fucCheckTEL (TEL) 
  ( 
  Var i, j, strTemp; 
  StrTemp = "0123456789 - () #"; 
  For (i = 0; i <TEL.length; i) 
  ( 
  J = strTemp.indexOf (TEL.charAt (i)); 
  If (j ==- 1) 
  ( 
  / / Characters that are not legitimate 
  Return 0; 
  ) 
  ) 
  / / Note legitimate 
  Return 1; 
  ) 

  / / Function: fucCheckLength 
  / / Function description: check the length of the string 
  / / Parameter Description: It is necessary to check the string 
  / / Return values: Length of 

  Function fucCheckLength (strTemp) 
  ( 
  Var i, sum; 
  Sum = 0; 
  For (i = 0; i <strTemp.length; i) 
  ( 
  If ((strTemp.charCodeAt (i)> = 0) & & (strTemp.charCodeAt (i) <= 255)) 
  Sum = sum 1; 
  Else 
  Sum = sum 2; 
  ) 
  Return sum; 
  ) 

Related articles:

Css attributes and the general use of filters
  Before finishing the article, although the standard does not support filters, but sometimes still feel it will be used, it again today to put forward, when there is a need for enquiries to be    Alpha: Setting transparency;    (Filter: alpha (opacity = opacity, finishop...
On the mouse wheel (key) programming, as well as the zoom zoom Css attribute example
  <! - Oh occasionally found the Internet, called Fengyun dance modified to cause the example of the role and how the operation can be seen IMG title attributes, the attention, only "with the mouse on the scroll effective" ->    <Img src = 'http://www.lshdic.co...
Ten website production know-how
  1 advance planning and designing the home may not be very difficult.    But this work and the preparation of traditional publicity materials, we need to be handled carefully and planning.    In other words, we must first determine their needs key message, and then made to...
"Love" a new advertising Xplus profitable advertising model
  "And the previous biggest difference between media advertising in that Xplus let you take the initiative to look at the target of your advertising, 'love' your advertising." March 30, the domestic network service platform magazine Xplus the new operators - Company CEO, in t...
Css page of the Style rolling - css style
  Css style details, page scrolling Style    The meaning of the statement is as follows:    Crollbar-Face-color: Rolling set of color pages;    - Color Scrollbar-Highlight: Rolling the left side of the slope and color settings;    Scrollbar-Shadow-Col...