JavaScript User registration Information validation

Source: Internet
Author: User

User registration information is verified correctly

One, JavaScript way


Second, regular expression validation

Apply Regular expression validation: User name 4-16 bit, beginning of letter ; username 4-16 bit, first letter capitalized ; two times the password is the same; phone number One by one and starting with 1 ; date of birth

in the The register.jsp script section code is as follows

<script language= "JavaScript" type= "Text/javascript" >

function Check ()

{

var Name=document.getelementbyid ("name"). Value;

var patrn_name=/^[a-za-z][a-za-z0-9]{3,15}$/; User name 4-16 bit, beginning of letter

if (name!=null&&!patrn_name.exec (name))

{

Alert (" user name input does not meet the requirements " +name);

return false;

}

var Pass1=document.getelementbyid ("Pass1"). Value;

var patrn_pass=/^[a-z][a-za-z0-9]{3,15}$/; username 4-16 bit, first letter capitalized

if (Pass1!=null&&!patrn_pass.exec (PASS1))

{

Alert (" password input does not meet the requirements , first letter Capital " +pass1);

return false;

}

if (Form1.pass1.value!=form1.pass2.value)

{

Alert (" password is different ");

Form1.pass1.focus ();

return false;

}

var Tel=document.getelementbyid ("Tel"). Value;

var   patrn_tel=/^[1][0-9]{10}$/; tel:13562276780

if (tel!=null&&!patrn_tel.exec (tel))

{

Alert ("Tel does not meet the requirements ");

return false;

}

var Csrq=document.getelementbyid ("Csrq"). Value;

var patrn_csrq=/^ (19|20) \d{2}-(1[0-2]|0?[ 1-9])-(0?[ 1-9]| [1-2]   [0-9]|3[0-1]) $/; csrq:2012-02-05

if (Csrq!=null&&!patrn_csrq.exec (CSRQ))

{

Alert ("csrq:2012-02-05");

return false;

}

return true;

}

</script>


This article is from the "Learn Without thinking" blog, please be sure to keep this source http://dyzyxy.blog.51cto.com/944775/1652125

JavaScript User registration Information validation

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.