This article describes how to use JavaScript to determine the length, number, Email, phone number, and other commonly used judgment functions. This article provides the implementation code directly. For more information, see
/*************************************** * *********************** // * Name: dataLength // * function: Calculate the Data Length // * entry parameter: fData: The data to be calculated // * exit parameter: returns the length of fData (Unicode length is 2, non-Unicode length is 1) //************************************** * ************************** function DataLength (fData) {var intLength = 0 for (var I = 0; I
255 )) intLength = intLength + 2 else intLength = intLength + 1} return intLength }//*********************** **************************************** * // * Name: isEmpty // * function: determines whether it is null // * entry parameter: fData: Data to be checked // * exit parameter: True: NULL/* False: non-empty //************************************ * *************************** function IsEmpty (fData) {return (fData = null) | (fData. length = 0 ))} //************************************** **** * ******************** // * Name: IsDigit // * function: determine whether it is a number. // * entry parameter: fData: Data to be checked. // * exit parameter: True: 0 to 9. // * False: it is not a number ranging from 0 to 9 //******************************** * ********************************* function IsDigit (fData) {return (fData> = "0") & (fData <= "9 "))} //************************************** * ************************* // * Name: isInteger // * function: determines whether it is a positive integer. // * entry parameter: fData: Data to be checked // * exit parameter: True: an integer, or the data is null // * False: Not an integer //************************************ * **************************** function IsInteger (fData) {// if it is null, return true if (IsEmpty (fData) return true if (isNaN (fData) | (fData. indexOf (". ")! =-1) | (fData. indexOf ("-")! =-1 )) return false return true }//*********************************: isEmail // * function: determines whether the Email address is correct. // * entry parameter: fData: The data to be checked. // * exit parameter: True: the correct Email address, or null // * False: incorrect Email address //********************************** * ****************************** function IsEmail (fData) {if (IsEmpty (fData) return true if (fData. indexOf ("@") =-1) return false var NameList = fData. split ("@"); If (NameList. length! = 2) return false if (NameList [0]. length <1) return false if (NameList [1]. indexOf (". ") <= 0) return false if (fData. indexOf ("@")> fData. indexOf (". ") return false if (fData. indexOf (". ") = fData. length-1) return false return true }//*********************************: isPhone // * function: determines whether the phone number is correct (including "()", "()", "+", "-", and spaces) // * entry parameter: fData: Data to be checked // * exit parameter: True: correct phone number, or blank // * False: incorrect phone number // * error message: //************************************** * ************************** function IsPhone (fData) {var str; var fDatastr = ""; if (IsEmpty (fData) return true for (var I = 0; I
= FLower) else return (fInput> = fLower) & (fInput <= fHigh ))}