A regular expression of the date of birth in JavaScript based on the ID card (you are given a review!) (containing the original 15 digits)) __java

Source: Internet
Author: User

The code is as follows:

Javascipt Code:

<script type= "Text/javascript" >
var reg = new RegExp ("^ (//d{6}) ((//d{2}) | ( D{4})) (//d{2}) (//d{2}) ((//d{4}) | ( D{3}X) | (//d{3})) $");
function Compute () {
var id = $ ("id");
var birth = $ ("Birth");
var idv = Id.value;
if (!reg.test (IDV)) {
Alert ("Sorry, your input format is incorrect.") ");
Id.focus ();
Return
}
var year = Idv.replace (Reg, "$");
if (year.length==2) {
Year= "+year";
}
var month = Idv.replace (Reg, "$");
var day = Idv.replace (Reg, "$");
Birth.value = "" + year + "years" + month + "Month" + Day + "days";
}
function $ (ID) {
return document.getElementById (ID);
}
</script>


Body:

<body>
    <form
         ID Number &nbsp;&nbsp;
        <input type= "text" id= "id"  />&nbsp;&nbsp;&nbsp; &nbsp;
        <input type= "button" value= "calculation" onclick= "compute ()"/><br/>
        Date of birth &nbsp;&nbsp;
        <input type= "text" id= "birth"  />
    </ Form>
</body>

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.