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