Common judgment functions such as JavaScript character length, number, Email, and phone sharing _ javascript tips-js tutorial

Source: Internet
Author: User
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 ))}
  
 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.