JS form Verification

Source: Internet
Author: User
Tags date of birth format




<SCRIPT>function Checkform () {if(Checkusername () &&checkpass () &&checkbirth () &&Checkemail ()) { return true; }Else{ return false; }}//user name non-null + length + legitimacy verificationfunction Checkusername () {varName =Document.myform.txtUser; if(name.value=="") {alert ("Please enter user name"); Name.focus (); return false; } if(name.value.length<4|| Name.value.length> -) {alert ("the user name is entered in a length of 4-16 characters"); Name.Select(); return false; } for(varI=0; i<name.value.length;i++) { varchartest=name.value.toLowerCase (). charAt (i); if( (! (chartest>='0'&& chartest<='9') && (!) ( chartest>='a'&& chartest<='Z')) && (chartest!='_') {alert ("The user name contains illegal characters and can only include letters, numbers, and underscores"); Name.Select(); return false; } } return true;}//password non-null + length + Password confirmation verificationfunction Checkpass () {varpass=Document.myform.txtPass; varrpass=Document.myform.txtRPass; if(pass.value=="") {alert ("The password cannot be empty"); Pass.focus (); return false; }if(pass.value.length<6|| Pass.value.length> -) {alert ("password length is 6-16 characters"); Pass.Select(); return false; } if(rpass.value!=pass.value) {Alert ("Confirm password inconsistent with password input"); Rpass.Select(); return false; } return true;}//Date of birth verificationfunction Checkbirth () {varBirth=Document.myform.txtBirth.value; if(birth=="") {alert ("please fill in the date of birth"); return false; }Else if(birth.length<Ten) {alert ("Birth date format error"); return false; }Else{ //intercept string to get date varYear=birth.substring (0,4); varMonth=birth.substring (5,7); varDay=birth.substring (8, birth.length); if(Birth.charat (4)!="-"|| Birth.charat (7)!="-"){//determine if the date meets the formatting requirementsAlert"date of birth format Yyyy-mm-dd"); Document.myform.txtBirth.Select(); return false; }Else if(IsNaN (year) | | IsNaN (month) | |IsNaN (Day)) {Alert ("the date must be a number"); Document.myform.txtBirth.Select(); return false; } varTime=NewDate (); if(Parseint (year,Ten) <1900|| parseint (Year,Ten) >time.getyear ()) {Alert ("date of birth range from 1900-"+time.getyear () +"years"); Document.myform.txtBirth.Select(); return false; }Else if(parseint (Month,Ten) <1|| parseint (Month,Ten) > A) {alert ("the month you entered is not between 1-12 months"); Document.myform.txtBirth.Select(); return false; }Else if(Parseint (Day,Ten) <1|| parseint (Day,Ten) > to) {alert ("the number of days you entered is not between 1-31"); Document.myform.txtBirth.Select(); return false; } } return true;}//Email Verificationfunction Checkemail () {varStremail=Document.myform.txtEmail; if(stremail.value.length==0) {alert ("e-mail cannot be empty!"); Stremail.focus (); return false; } if(StrEmail.value.indexOf ("@",0)==-1) {alert ("e-mail format is incorrect \ n must contain the @ symbol! "); Stremail.Select(); return false; } if(StrEmail.value.indexOf (".",0)==-1) {alert ("The e-mail format is incorrect \ n must contain a. symbol! "); Stremail.Select(); return false; } return false;}</SCRIPT>



JS form Verification

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.