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

Source: Internet
Author: User

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 5, 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 11 9 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148-149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170-171 /****************************************************************//* Name: datalength//* function: Calculate the length of the data//* Entry parameters: Fdata: Data//* export parameters that need to be computed: the length of the return Fdata (Unicode length 2, non-Unicode length 1)//********************************************** function Datalength (fdata) {var intlength=0 for (Var i=0;i<fdata.length;i++) {if (fdata.charcod EAt (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: null//* False: Non-empty//*********** function IsEmpty (fdata) {return (fdata==null) | | (fdata.length==0)) }    //****************************************************************//* name: isdigit//* function: To determine whether a digital//* entry Parameters: Fdata: Data//* export parameters to check: True: is 0 to 9 of the number//* False: not 0 to 9 of the number//******************************************************** ******function IsDigit (fdata) {return (fdata>= "0") && (fdata<= "9"))}    //********************* * Name: Isinteger//* function: To determine whether a positive integer//* entry parameter: Fdata: Data to check//* exit parameter: True: is an integer, or The person data is empty//* False: Is not an integer//***************************************************************** function isinteger (fData) {//If NULL, returns True if (IsEmpty (Fdata)) return True if (isNaN (fdata) | | (Fdata.indexof (".")! =-1) | | (Fdata.indexof ("-")!=-1) return false   return true}  //****************************************************************//* name: Isem Ail//* function: To determine whether it is the correct email address//* entry parameters: Fdata: Data to check//* exit parameters: 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 of 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}  //********************************************************* * 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 to return true}  //************************************************************* * Name: Isplusnumeric//* function: Determine if the correct positive number (can contain a decimal part)//* entry parameters: Fdata: Data to check//* exit parameter: true: Correct positive number, or null//* False: Error positive//* 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)) return True if (isNaN ( Fdata)) return false   return true}    //************************************************************* * Name: Isintegerinrange//* function: To determine whether a number is within the specified range//* entry parameters: Finput: The data to be checked//* fLower: Check the lower bounds, if there is no lower limit, please use null//* fhigh: Check The upper limit, if there is no upper limit, please use null//* exit parameter: True://* False in the specified range: Outside the specified range//******************************************************** function Isintegerinrange (Finput,flower,fhigh) {if (flower==null) return (fInPut<=fhigh) Else if (fhigh==null) return (finput>=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.