First stage: Front-end development _ use JS to complete the registration page form Verification

Source: Internet
Author: User

2018-06-04

use JS to complete the registration page form Check

First, Step realization

 First step: Determine the event (onsubmit) and bind it to a function

Step Two: Write this function (get user input data < need to define a id> at the specified location when getting data)

Step three: Judge the data entered by the user

Fourth Step: Data legal (let form submit)

Fifth step: illegal data (give error message, do not allow form to submit)

question: How do I control form submission?

about event onsubmit: typically used for form submission, it is necessary to give a return value when defining a function. such as: onsubmit = return Checkform ()

Second, the Code implementation

JS Code:

<script>
function checkform () {
//alert ("AA"); /** Verify username * ///1. Gets the data entered by the user var uvalue = document.getElementById ("user"). Value;            
   // alert (uvalue); if (uvalue== "") {//2. Error message alert ("User name cannot be empty!")    ); return false/;}
* Check password */var pValue = document.getElementById ("password"). Value;   
if(pvalue== "") {  
alert ("Password cannot be empty!")     ); return false; } /** Verify the password */var rpvalue = document.getElementById ("Repassword"). Value;   
if(rpvalue!=pvalue) {   
alert ("Two times password input is inconsistent!")     ); return false; }/ * Verify mailbox */var evalue = document.getElementById ("Eamil"). Value;   
If(!/^ ([a-za-z0-9_-]) [email protected] ([a-za-z0-9_-]) + (. [ A-za-z09_-]) +/.test (Evalue)) {  
alert ("The mailbox format is incorrect!")      ); return false;
}
}
</script>

Html section:

<action= "#"  method= "Get"  name= "RegForm"  onsubmit= "return Checkform ()">

Need to add ID at specified location

First stage: Front-end development _ use JS to complete the registration page 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.