JavaScript-Regular Expressions

Source: Internet
Author: User

Regular expressions
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" ><html><head><meta http-equiv="Content-type" Content="text/html; Charset=utf-8 "><title>Regular expressions</title><style type="Text/css"> . Ok{  background: url (images/ok.gif) no-repeat; }    </style><script type="Text/javascript">     //Date of birth is between 1900-2014 and the format is YYYY-MM-DD      function checkbirthday(){        varregbirthday=/^ (19\d{2}|200\d|201[0-4])-(0?[ 1-9]|1[0-2])-(0?[ 1-9]| [1-2]\d|3[0-1]) $/;varbirthday=$ ("Birthday"). Value;if(!regbirthday.test (Birthday)) {            $("Birthdayinfo"). style.color="#f00"; $("Birthdayinfo"). innerhtml="* format is not correct, date of birth is between 1900-2014 and the format is Yyyy-mm-dd"; $("Birthdayinfo"). classname=""; }Else{            $("Birthdayinfo"). innerhtml="&nbsp;&nbsp;&nbsp;&nbsp;"; $("Birthdayinfo"). classname="OK"; }     }//Mobile number, 11-bit, starting at 1     function checkmobile(){        varregmobile=/^1\d{10}$/;varmobile=$ ("mobile"). Value;if(!regmobile.test (MOBILE)) {            $("Mobileinfo"). style.color="#f00"; $("Mobileinfo"). innerhtml="* Mobile phone number, 11-bit, start at 1"; $("Mobileinfo"). classname=""; }Else{            $("Mobileinfo"). innerhtml="&nbsp;&nbsp;&nbsp;&nbsp;"; $("Mobileinfo"). classname="OK"; }    }//ZIP code, 6-bit, first not 0     function checkcode(){        varRegcode=/^[1-9]\d{5}$/;varcode=$ ("Code"). Value;if(!regcode.test (code)) {            $("Codeinfo"). style.color="#f00"; $("Codeinfo"). innerhtml=* ZIP code, 6 digits, first not 0 "; $("Codeinfo"). classname=""; }Else{            $("Codeinfo"). innerhtml="&nbsp;&nbsp;&nbsp;&nbsp;"; $("Codeinfo"). classname="OK"; }               }//user name, consisting of letters, numbers, underscores, dots, dashes, and Chinese characters,    //can only start or end with a number, letter, and length of 6-14     function checkusername(){        varRegusername=/^ ([\d|[ A-z]) ([\u4e00-\u9fa5\w.-]) {4,12} ([\d|[ A-z]) $/i;varusername=$ ("username"). Value;if(!regusername.test (username)) {            $("Usernameinfo"). style.color="#f00"; $("Usernameinfo"). innerhtml="* User name, consisting of letters, numbers, underscores, dots, dashes, and Chinese characters"; $("Cusernameinfo"). classname=""; }Else{            $("Usernameinfo"). innerhtml="&nbsp;&nbsp;&nbsp;&nbsp;"; $("Usernameinfo"). classname="OK"; }}/^\d| [A-z] {4,Ten}$/;//password, can only be composed of letters and numbers, length is 4-10 bits     function checkpwd(){        varRegpwd=/^[a-za-z0-9]{4,10}$/;varpwd=$ ("PWD"). Value;if(!regpwd.test (PWD)) {            $("Pwdinfo"). style.color="#f00"; $("Pwdinfo"). innerhtml="* Password, only consists of letters and numbers, length 4-10 bits"; $("Pwdinfo"). classname=""; }Else{            $("Pwdinfo"). innerhtml="&nbsp;&nbsp;&nbsp;&nbsp;"; $("Pwdinfo"). classname="OK"; }                   }//Age, 1-120     function checkage(){        varRegage=/^ (1[0-1]|[ 1-9])? \d$/;varage=$ ("Age"). Value;if(!regage.test (age)) {            $("Ageinfo"). style.color="#f00"; $("Ageinfo"). innerhtml="* Age, 1-120"; $("Ageinfo"). classname=""; }Else{            $("Ageinfo"). innerhtml="&nbsp;&nbsp;&nbsp;&nbsp;"; $("Ageinfo"). classname="OK"; }               }//Determine the format of the ID card (requires support for new and old certificates)     function checkidcard(){        varregidcard=/^[1-9]\d{14} (\d{2}[0-9x])? $/;varidcard=$ ("Idcard"). Value;if(!regidcard.test (Idcard)) {            $("Idcardinfo"). style.color="#f00"; $("Idcardinfo"). innerhtml="* Not a generation or a second-generation ID card! "; $("Idcardinfo"). classname=""; }Else{            $("Idcardinfo"). innerhtml="&nbsp;&nbsp;&nbsp;&nbsp;"; $("Idcardinfo"). classname="OK"; }               }//     function checkphone(){}//Determine email address     function checkemail(){        varRegemail=/^\[email protected]\w+ (\.[ a-za-z]{2,3}) {1,2}$/;varemail=$ ("Email"). Value;if(!regemail.test (email)) {            $("EmailInfo"). style.color="#f00"; $("EmailInfo"). innerhtml="* Email address is not correct! "; $("EmailInfo"). classname=""; }Else{            $("EmailInfo"). innerhtml="&nbsp;&nbsp;&nbsp;&nbsp;"; $("EmailInfo"). classname="OK"; }               } function $(ID){        returndocument.getElementById (ID)}</script></head><body>Date of birth:<input type="text" id="Birthday" onblur ="Checkbirthday ()"/><span id="Birthdayinfo"></span><br/>Mobile Number:<input type="text" id="mobile" onblur= "Checkmobile ()"/><span id="Mobileinfo"></span><br/>Zip code:<input type="text" id= "code" onblur="Checkcode () "/><span id="Codeinfo"></span><br/>User name:<input type="text" id="username" onblur=" Checkusername () "/><span id="Usernameinfo"></span><br/>Password:<input type="password" id="pwd" onblur="Checkpwd () "/><span id="Pwdinfo"></span><br/>Age:<input type= "text" id= "age" onblur="Checkage ()" /><span id="Ageinfo"></span><br/>Id:<input type="text" id="Idcard" onblur=" Checkidcard () "/><span id="Idcardinfo"></span><br/>Fixed phone:<input type="text" id= "phone" onblur="Checkphone () "/><span id="Phoneinfo"></span><br/>E-Mail:<input type="text" id="Email" onblur="Checkemail () "/><span id="EmailInfo"></span><br/></body></html>

JavaScript-Regular Expressions

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.