JavaScript to judge the character length, number, Email, telephone and other common judgment functions to share _javascript skills

Source: Internet
Author: User
/****************************************************************//* Name: datalength//* function: Calculate the length of the data//* entry parameters: FData: Need Calculated data//* exit Parameters: Returns the length of the Fdata (Unicode length is 2, non-Unicode length is 1)//*********************************************************** function Datalength (fdata) {var intlength=0 for (Var i=0;i<fdata.length;i++) {if (Fdata.charcodeat ( i) < 0) | |
      (Fdata.charcodeat (i) > 255)) Intlength=intlength+2 Else intlength=intlength+1} return intlength}//********************************       * Name: IsEmpty//* function: To determine whether null//* entry parameters: Fdata: Data to check//* exit parameter: True: Empty//* False: Non-empty//***************************************************************** function IsEmpty (fdata) {return (FD Ata==null) | |
(fdata.length==0)) //****************************************************************//* Name: isdigit//* function: To determine whether the number//* entry parameters: FData: To Checked data//* exit parameters: True: 0 to 9 digits//* False: not 0 to 9 digits/function IsDigit (fdata) {return (fdata>= "0") && (fdata<= "9")}//****************************************************************//* Name: IsInteger// * Function: To determine whether a positive integer//* entry parameter: Fdata: The data to be checked//* exit parameter: True: is an integer, or the data is empty//* False: not an integer//********************** function Isinteger (fdata) {//If NULL, returns True if (IsEmpty (fdata)) return T Rue if (isNaN (fdata)) | | (Fdata.indexof (".")! =-1) | |
    (Fdata.indexof ("-")!=-1)
return false to return true}//****************************************************************//* name: Isemail * Function: To determine whether the correct email address//* entry parameters: Fdata: Data to be checked//* exit parameter: true: Correct email address, or null//* false: Wrong 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 is False if (NAMELIST[0].LENGTH&LT;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 to return true}//****************************************************************               
* Name: Isphone//* function: To determine whether the correct phone number (can contain "()", "()", "+", "-" and space)//* entry parameters: Fdata: To check the data//* export parameters: true: Correct phone number, or empty * False: Wrong phone number//* error message://***************************************************************** function Isphone
(Fdata)
  {var str;
  var fdatastr= "";
    if (IsEmpty (Fdata)) return True for (Var i=0;i<fdata.length;i++) {str=fdata.substring (i,i+1); if (str!= "&& str!=") "&& str!=" ("&& str!=") "&& str!=" + "&& str!="-"&&amp ;
  Str!= "") fdatastr=fdatastr+str; 
  }//alert (FDATASTR); if (isNaN (FDATASTR)) retUrn false return true}//****************************************************************//* name: Isplusnumeric/ /* Function: Determine if the correct positive number (can contain a decimal part)//* entry parameter: Fdata: The data to be checked//* exit parameter: true: Correct positive number, or null//* false: Wrong positive number//* error message:// function Isplusnumeric (fdata) {if IsEmpty (fdata ) return True if ((isNaN (fdata)) | |
    (Fdata.indexof ("-")!=-1) return false to return true}//****************************************************************//* name: IsNumeric// * Function: Determine if the correct number (can be negative, decimal)//* entry parameters: Fdata: The data to be checked//* exit parameter: true: correct number, or null//* false: Wrong number//* error message:// function IsNumeric (fdata) {if (IsEmpty (Fdata)) re Turn True if (isNaN (Fdata)) return False to return true}//*********************************************** * Name: Isintegerinrange//* function: To determine whether a number in the specified range//* entry parameters:Finput: To check the data//* fLower: Check the lower bounds, if there is no lower limit, please use null//* fhigh: Check the upper limit, if there is no limit, please use null//* exit parameter: True: within the specified range * False: Outside the specified range//***************************************************************** function Isintegerinrange (fIn Put,flower,fhigh) {if (flower==null) return (Finput<=fhigh) else if (fhigh==null) return (Finput>=flowe R) 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.