ShuDudu's Home was started in 2011, but the web data is lost, so now begin again, I would like to make some friends, I hope you like ShuDudu's home.
Current position: ShuDudu > Life >

[JS]Several commonly used form judgments

Thursday on June 9th, 2005Life

[JS] several commonly used form judgments

//function name: chksafe

//function name: chksafe//function description: check whether it contains & quot;'",'\\', & quot;/"//Parameter description: the string to be checked//return value: 0: yes: 1: noFunction chksafe (a){Return 1/* fibdn = new Array (& quot;'", & quot;\\ & quot;,", & quot;,", & quot;,"; & quot;,"/& quot;)I=fibdn.lengthJ=a.lengthFor (ii=0;ii 

//function name: chkspc

//function name: chkspc//function description: check whether there are spaces//Parameter description: the string to be checked//return value: 0: yes: 1: noFunction chkspc (a){Var i=a.lengthVar j = 0Var k = 0While (kumbltteri){If (a.charAt (k)! = & quot; & quot;)J = jroom1K = kumb1}If (jacks 0){Return 0}If (iSuppli j){return 2;}Else{Return 1}} 

//function name: chkemail

//function name: chkemail//function description: check whether it is Email Address//Parameter description: the string to be checked//return value: 0: not 1: yesFunction chkemail (a){var i=a.lengthVar temp = a.indexOf ('@')Var tempd = a.indexOf ('.')If (temp & gt; 1) {If ((i-temp) & gt; 3) {If ((i-tempd) & gt;0) {Return 1}}}Return 0}//opt1 decimal opt2 negative number//when opt2 is 1, check whether num is negative.//check whether num is a decimal when opt1 is 1//return 1 is correct, 0 is wrongFunction chknbr (num,opt1,opt2){Var i=num.lengthVar staus//staus is used for recording. The number ofStatus=0If ((opt2roomroom1) & & (num.charAt (0) = ='-')){//alert (& quot;You have enter an invalid number.")Return 0}//when the last one is. An error occurred at the timeIf (num.charAt (iMur1) ='.'){//alert (& quot;You have enter an invalid number.")Return 0}For (jobo _ share _ lttern _ share _ I _ match +){If (num.charAt (j) = ='.'){Status++}If (status>1){//alert (& quot;You have enter an invalid number.")Return 0}If (num.charAt (j) & lt;'0' | | num.charAt (j) & gt;'9'){If (opt1==0) | | (num.charAt (j)! ='.') & & (jackers 0){//alert (& quot;You have enter an invalid number.")Return 0}}}Return 1} 

//function name: chkdate

//function name: chkdate//function description: check whether it is a date//Parameter description: the string to be checked//return value: 0: not date 1: dateFunction chkdate (datestr){Var lthdatestrIf (datestr! = & quot;")Lthdatestr= datestr.lengthElseLthdatestr=0Var tmpy=""Var tmpm=""Var tmpd=""//var datestrVar statusStatus=0If (lthdatestr== 0)Return 0For (lthdatestrististi +){if (datestr.charAt (I) = ='-'){Status++}If (status>2){//alert (& quot;Invalid format of datestamped quot;)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.roomthread4) | | (tmpm.length>2) | | (tmpd.length>2)){//alert (& quot;Invalid format of datestamped quot;)Return 0}If (!) & & (12 percent) & & (31 percent) & & (1 percent)){//alert (& quot;Invalid month or daylights quot;)Return 0}If (! (year% 4) = = 0) & & (month==2) & & (day==29)){//alert (& quot;This is not a leap yearbook qualified quot;)Return 0}If ((month<=7) & & ((month% 2) = = 0) & & (day>=31)){//alert (& quot;This month is a small monthically qualified quot;)Return 0}If ((month>=8) & & ((month% 2) = = 1) & & (day>=31)){//alert (& quot;This month is a small monthically qualified quot;)Return 0}If ((month==2) & & (day==30)){//alert (& quot;The Febryary never has this daylights quot;)Return 0}Return 1} 

//function name: fucPWDchk

//function name: fucPWDchk//function description: check whether it contains non-numbers or letters//Parameter description: the string to be checked//return value: 0: contains 1: all numbers or lettersFunction fucPWDchk (str){Var strSource = & quot;0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"Var chVar iVar tempFor (iTunes) = (str.length-1) +){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) = & quot; & quot;){str=str.substr (1);}While (str.charAt (str.length-1) = & quot; & quot;){str=str.substr (0sperm str.bearthmur1);}Return (str)} 

//function name: fucCheckNUM

//function name: fucCheckNUM//function description: check whether it is a number//Parameter description: the number to be checked//return value: 1 is a number, 0 is not a numberFunction fucCheckNUM (NUM){Var i,j,strTempStrTemp="0123456789"If (NUM.length== 0)Return 0For (iDeposit ittermitnu/nu/lttern/nu.{J=strTemp.indexOf (NUM.charAt (I))If (jacks music 1){//indicates that there are characters rather than numbersReturn 0}}//description is a numberReturn 1} 

//function name: fucCheckTEL

//function name: fucCheckTEL//function description: check whether it is a phone number//Parameter description: the string to be checked//return value: 1 is legal, 0 is illegalFunction fucCheckTEL (TEL){Var i,j,strTempStrTemp="0123456789- () # & quotFor (I/O/T/T/{J=strTemp.indexOf (TEL.charAt (I))If (jacks music 1){//indicates that some characters are illegal.Return 0}}//indicate that it is legalReturn 1} 

//function name: fucCheckLength

//function name: fucCheckLength//function introduction: check the length of the string//Parameter description: the string to be checked//return value: length valueFunction fucCheckLength (strTemp){Var i,sumSum=0For (itemism itteristic strTemp.interthistialism +){If ((strTemp.charCodeAt (I) & gt;=0) & & (strTemp.charCodeAt (I) & lt;=255))Sum=sum+1ElseSum=sum+2}Return sum} 

Copyright Protection: ShuDudu from the original article, reproduced Please keep the link: https://www.shududu.com/life/JS-Several-commonly-used-form-judgments.htm