Regular Expression Validation form

Source: Internet
Author: User

Good JS authentication ~~~~~~~~~~~~~~~~~~~~~~~~~ use: Verify the format of the IP address input: STRIP:IP address return: False If True is returned by validation; */function IsIP (StrIP) {if ( IsNull (StrIP)) return false; var re=/^ (\d+) \. (\d+) \. (\d+) \. (\d+) $/g//match the regular expression of the IP address if (re.test (StrIP)) {if (regexp.$1 <256 && regexp.$2<256 && regexp.$3< && regexp.$4<256) return true; } return false; }/* Use: Check that the input string is empty or that all spaces are input: str Returns TRUE if all is empty, otherwise false */function IsNull (str) {if (str = = = "") to return; var Regu = "^[]+$"; var re = new RegExp (Regu); return Re.test (str); }/* Purpose: Check that the value of the input object conforms to the integer format input: string returned by str input: False If True is returned by validation */function Isinteger (str) {var regu =/^[-]{0,1}[0-9]{ 1,}$/; return Regu.test (str); }/* Use: Check that the input phone number is entered correctly: S: String returns: False if True is returned by validation */function Checkmobile (s) {var regu =/^[1][3][0-9]{9}$/; var Re = new RegExp (Regu); if (Re.test (s)) {return true;} else{return false;}} /* Purpose: Check if input string conforms to positive integer format input: S: string return: False If True is returned by validation */function Isnumber (s) {var regu = "^[0-9]+$ "; var re = new RegExp (Regu); if (S.search (re)! =-1) {return true;} else {return false;}} /* Purpose: Check if the input string is a numeric format with decimals, can be negative input: s: string return: False If True is returned by validation */function Isdecimal (str) {if (Isinteger (str)) retur n true; var re =/^[-]{0,1} (\d+) [\.] + (\d+) $/; if (Re.test (str)) {if (regexp.$1==0&&regexp.$2==0) return false; return true;} else {return false;}} /* Purpose: Check that the value of the input object conforms to the port number format input: string returned by str input: False If True is returned by validation */function isport (str) {return (Isnumber (str) &&amp ; str<65536); }/* Purpose: Check whether the value of the input object conforms to the e-mail format input: string returned by str input: False If True is returned by validation */function Isemail (str) {var myreg =/^[-_a-za-z0- 9][email protected] ([_a-za-z0-9]+\.) +[a-za-z0-9]{2,3}$/; if (Myreg.test (str)) return true; return false; }/* Purpose: Check that the input string conforms to the amount format defined as a positive number with decimals, up to three digits after the decimal point: S: string return: False If True is returned by validation */function Ismoney (s) {var regu = "^[ 0-9]+[\.] [0-9] {0,3}$ "; var re = new RegExp (Regu); if (Re.test (s)) {return true;} else {return false;}} /* Purpose: Check whether the input string is only in EnglishLetters and numbers and underscores input: s: String returns: True if verified, returns false */function Isnumberor_letter (s) {//Determines whether the number or letter var Regu = "^[0-9a-za-z\_ ]+$"; var re = new RegExp (Regu); if (Re.test (s)) {return true;} else{return false;}} /* Purpose: Check that the input string is only composed of English letters and numbers input: s: string return: False If True is returned by validation */function Isnumberorletter (s) {//Determines whether the number or the letter var Regu = "^[0-9a-za-z]+$"; var re = new RegExp (Regu); if (Re.test (s)) {return true;} else{return false;}} /* Purpose: Check that the input string is entered only by Chinese characters, letters, and Numbers: value: String return: False If True is returned by validation */function Ischinaornumborlett (s) {///Determine whether it is a Chinese character, letter, The number consists of var Regu = "^[0-9a-za-z\u4e00-\u9fa5]+$"; var re = new RegExp (Regu); if (Re.test (s)) {return true;} else{return false;}} /* Use: Determine if date input: Date: day; FMT: Date format returns: False if True is returned by validation */function isDate (date, FMT) {if (fmt==null) fmt= "YyyyMMdd "; var yindex = fmt.indexof ("yyyy"); if (yindex==-1) return false; var year = date.substring (yindex,yindex+4); var mindex = Fmt.indexof ("MM"); if (mindex==-1) return false; var month = Date.substriNg (mindex,mindex+2); var dindex = Fmt.indexof ("dd"); if (dindex==-1) return false; var day = date.substring (dindex,dindex+2); if (!isnumber (year) | | Year> "2100" | | year< "1900") return false; if (!isnumber (month) | | Month> "12" | | month< "") return false; if (Day>getmaxday (year,month) | | day< "") return false; return true; } function Getmaxday (year,month) {if (month==4| | month==6| | month==9| | month==11) return "30"; if (month==2) if (year%4==0&&year%100!=0 | | year%400==0) return "29"; else return "28"; return "31"; }/* Use: Character 1 to end input with string 2: str1: string; str2: String returned: False if True is returned by validation */function Islastmatch (STR1,STR2) {var index = s Tr1.lastindexof (STR2); if (str1.length==index+str2.length) return true; return false; }/* Use: Character 1 is entered as String 2: str1: string; str2: The contained string returns: False if True is returned by validation */function Isfirstmatch (STR1,STR2) {var index = Str1.indexof (STR2); if (index==0) return true; return false; }/* Use: Character 1 is a string containing 2 input: str1: string; str2: The contained string returns: False if True is returned by validation */FUnction IsMatch (STR1,STR2) {var index = Str1.indexof (STR2), if (index==-1) return false; return true;}/* Use: Check that the input start and end date is positive True, the rule is formatted correctly for two dates, and ends as expected >= start date input: StartDate: Start date, string endDate: End as expected, string return: false */function if returned by validation Checktwodate (startdate,enddate) {if (!isdate (startdate)) {alert ("Start date incorrect!"); return false;} else if (!isdate (endDate ) {alert ("Incorrect end date!"); return false;} else if (StartDate > EndDate) {alert ("Start date cannot be greater than End date!"); return false;} retur n true; }/* Use: Check that the input email format is entered correctly: Stremail: string return: False If True is returned by validation */function Checkemail (stremail) {//var Emailreg = /^[_a-z0-9][email protected] ([_a-z0-9]+\.) +[a-z0-9]{2,3}$/; var Emailreg =/^[\w-]+ (\.[ \w-]+) *@[\w-]+ (\.[ \w-]+) +$/; if (Emailreg.test (Stremail)) {return true;} else{alert ("The email address you entered is not in the correct format!) "); return false; }}/* Use: Check that the input phone number format is entered correctly: Strphone: string return: False If True is returned by validation */function Checkphone (strphone) {var phoneregwit Harea =/^[0][1-9]{2,3}-[0-9]{5,10}$/; var Phoneregnoarea =/^[1-9]{1}[0-9]{5,8}$/; var prompt = "The phone number you entered is incorrect!" if (Strphone.length > 9) {if (Phoneregwitharea.test (Strphone)) {return true;} else{alert (prompt); return false;}} else{if (phoneregnoarea.test (Strphone)) {return true;} else{alert (prompt); return false;}} }/* Purpose: Check the number of checkboxes selected Enter: Checkboxid: String return: Returns the number of selected in this check box */function Checkselect (CHECKBOXID) {var check = 0; var i=0; I F (document.all (CHECKBOXID). length > 0) {for (i=0; i 127) TotalCount + = 2; else totalcount++; } return totalcount; } function Getfirstselectedvalue (CHECKBOXID) {var value = null; var i=0; if (document.all (CHECKBOXID). length > 0) {F or (i=0; i 0) {for (i=0; i 0) {for (i=0; i 0) {for (i=0; i "2100" | | year< "1900") return false; var month = value.substring (4,6); if (month> "| | | month<") return false; var day = value.substring (6,8); if (Day>getmaxday (year,month) | | day< "") return false; return true; }/* Use: Check that the input start and end date is correct, that the rule is formatted correctly for two dates or is empty, and that the ending date >= the starting Date input: StartDate: Start date, string endDate: End Date, string return: If True is returned by validation, otherwise returns false */function Checkperiod (startdate,enddate) {if (!checkdate (startdate)) {alert ("Start date incorrect!"); return false;} else if (!checkdate (endDate)) {alert ("End date incorrect!"); return false;} else if (StartDate > EndDate) {alert ("Start date cannot be greater than terminating Date! "); return false; } return true; }/* Use: Check that the security code is entered correctly: Seccode: Security Code return: False If True is returned by validation */function Checkseccode (seccode) {if (Seccode.length! = 6) {alert ("Security code should be 6 bits"); return false;} if (!isnumber (Seccode)) {alert ("Security code can contain only numbers"); return false;} return true; }/**************************************************** Function:ctrim (sinputstring,itype) Description: A function of string de-whitespace Parameters:itype:1= GoDrop the space to the left of the string 2= Remove the space to the left of the string 0= remove the left and right spaces of the string return value: A string that strips away the space ****************************************************/ function Ctrim (sinputstring,itype) {var stmpstr = '; var i =-1; if (IType = = 0 | | iType = 1) {while (stmpstr = = ') { ++i; Stmpstr = Sinputstring.substr (i,1); } sinputstring = sinputstring.substring (i); if (IType = = 0 | | iType = = 2) {stmpstr = "; i = sinputstring.length; while (stmpstr = =") {-I; stmpstr = Sinputstri Ng.substr (i,1); } sinputstring = Sinputstring.substring (0,i+1); } return sinputstring; }/* var regu =/\w*[0-9]+\w*$/; var regu2 =/\w*[a-za-z]+\w*$/; var newpassword = $ ("#ipt_initial_password"). Val (). replace (/[]/g, ""); if (!regu.test (newpassword) | |!regu2.test (newpassword)) {showmessage ("Password must contain letters and numbers!", "system hint"); $ ("#ipt_initial_ Password "). AddClass (" error "); $ ("#ipt_initial_password"). focus (); return false; }

Regular expression Validation form

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.