[JavaScript] Several common form input judgment

xiaoxiao2021-03-06  88

// Function Name: Chksafe // Features: Check if "'",' // ', "/" // Parameter Description: String // Return Value: 0: Yes 1: Not Function Chksafe a) {RETURN 1; / * fibdn = new array ("'", "//", ",", ";", "/"); i = fibdn.length; j = a.length For (ii = 0; II

// Function name: Chkspc // function introduction: Check if it contains space // parameter description: The string to check // return value: 0: Yes 1: not function chkspc (a) {var i = a.length; var J = 0; var k = 0; while (k

// Function Name: Chkemail // Features: Check if the email address // Parameter Description: String // Return Value: 0: Not 1: Yes 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 decimal OPT2 negative number // Check NUM if the OPT2 is 1:// When the OPT1 is 1, check whether NUM is decumbion // Return 1 is correct, 0 is the wrong Function CHKNBR (Num, OPT1, OPT2 ) {Var i = Num.length; var staus; // staus is used to record. The number status = 0; IF ((OPT2! = 1) && (Num.Charat (0) == '-')) { // Alert ("You Have Enter A Invalid Number."); Return 0;} // When the last bit is. Error IF (Num.Charat (I-1) == '.') {// alert "You Have Enter a invalid Number."); Return 0;}

For (j = 0; j 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 Name: chkdate // Features: Check if the date // Parameter Description: String // Return Value: 0: Not Date 1: Yes 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 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)} f ((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 DAY!"); Return 0;} Return 1;} // function name: fucpwdchk // function introduction: Check if there is a non-numeric or letter // parameter description: To check // string return value: 0: 1 comprising: all numbers or letters function fucPWDchk (str) {var strSource = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; var ch; var i; var temp; for (i = 0; i <= ( Str.l ENGTH-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.sustr (1);} while (str.charat (str.length-1) == "") {str = Str.Substr (0, str.Length-1);} return (str);} // function name: fucchecknum // function introduction: Check if it is a number // parameter description: To check the number // return value: 1 In order to be a number, 0 is not digital function fucchecknum (num) {var i, j, strTemp; startemp = "0123456789"; if (num.length == 0) Return 0 for (i = 0; i

// Function name: fucchecktel // function introduction: Check if the phone number // parameter description: The string // return value to check: 1 is legal, 0 is the illegal function fucchecktel (tel) {var i, j , strtemp; strTemp = "0123456789 - () #"; for (i = 0; i

// Function name: Fucchecklength // function introduction: Check the length of the string // Parameter Description: String // Return Value: Length value Function Fucchecklength (strTemp) {var i, sum; sum = 0; for i = 0; i = 0) && (Strtemp.Charcodeat (i) <= 255)) SUM = SUM 1; Else Sum = SUM Return Sum;}

转载请注明原文地址:https://www.9cbs.com/read-104961.html

New Post(0)