JS simple implementation of user registration information verification Code _JAVASCRIPT skills

Source: Internet
Author: User

Register.html

Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> User Registration </title>
<style type= "Text/css" >
@import "Css/userregister.css";
</style>
<body id= "Body" >
<div id= "Div_form" >
<form method= "post" action= "url" >
<table id= "Table" >
<tbody>
<tr>
<td> User name:</td>
<td>
<input name= "username" id= "username" type= "text" onfocus= "Showdesc (This)" onblur= "Checktext (This)"/>
</td>
</tr>
<tr>
<td> Password:</td>
<td>
<input name= "password" id= "password" type= "text" onfocus= "Showdesc (This)" onblur= "Checktext (This)"/>
</td>
</tr>
<tr>
<td> Confirm Password:</td>
<td>
<input name= "Password2" id= "PASSWORD2" type= "text" onfocus= "Showdesc (This)" onblur= "Checktext (This)"/>
</td>
</tr>
<tr>
<td> ID Number:</td>
<td>
<input name= "IDNumber" id= "IDNumber" type= "text" onfocus= "Showdesc (This)" onblur= "Checktext (This)"/>
</td>
</tr>
<tr>
<td> Phone number:</td>
<td>
<input name= "PhoneNumber" id= "PhoneNumber" type= "text" onfocus= "Showdesc (This)" onblur= "Checktext (This)"/>
</td>
</tr>
<tr>
<td>Email:</td>
<td>
<input name= "Email" id= "email" type= "text" onfocus= "Showdesc (This)" onblur= "Checktext (This)"/>
</td>
</tr>
<tr>
<td> </td>
&LT;TD align= "Right" >
<input type= "Submit" value= "Confirm Submission"/>
</td>
</tr>
</tbody>
</table>
<table id= "TABLE2" border= "0" >
<tr><td><span id= "username" > Please enter user name </span></td></tr>
<tr><td><span id= "Password" > Please enter password </span></td></tr>
<tr><td><span id= "Password2" > Please enter your password again </span></td></tr>
<tr><td><span id= "IDNumber" > Please enter your ID number </span></td></tr>
<tr><td><span id= "PhoneNumber" > Please enter phone number </span></td></tr>
<tr><td><span id= "Email" > Please enter your email address </span></td></tr>
</table>
</form>
</div>
<script type= "Text/javascript" src= "Jslib/registercheck.js" >
</script>
</body>

Registercheck.js

Copy Code code as follows:

When the input box gets focus, the prompt is displayed
function Showdesc (obj)
{
var id= obj.name;
document.getElementById (ID). style.display= "inline";
}

Verify that the input is valid when the input box loses focus
function Checktext (obj)
{
Get the ID value of the input box
var id= obj.name;
var Text=document.getelementbyid (id.tostring (). toUpperCase ()). Value;

To determine if it is empty
if (Text.replace (/\s/g, "") = "")
{
document.getElementById (ID). innerhtml= "Input cannot be empty";
}
Else
{
Assembly method
Convert first letter to uppercase, remaining unchanged
var firstchar=id.charat (0). toString (). toUpperCase ();
//
var strsub=id.substring (1,id.length);
var strmethod= "Check" +firstchar+strsub+ "()";
var isTrue = eval (strmethod);
if (isTrue)
{
document.getElementById (ID). innerhtml= "Input valid";
}
}


}

function Checkusername ()
{
Simply judge the length of the user name
var id = document.getElementById ("USERNAME");
var Username=id.value;
if (Username.length > 10)
{
document.getElementById (id.name). InnerHTML = "The user name entered is too long";
return false;
}
Else
return true;
}
function Checkpassword ()
{
var password = document.getElementById ("password"). Value;
return true;
}
function CheckPassword2 ()
{
var Id=document.getelementbyid ("PASSWORD");
var Id2=document.getelementbyid ("PASSWORD2");
var password = id.value;
var password2 = Id2.value;
if (PASSWORD!=PASSWORD2)
{
document.getElementById (id.name). innerhtml= "Inconsistent passwords";
return false;
}
return true;
}
function Checkidnumber ()
{
var Id=document.getelementbyid ("IDNUMBER");
var IDNumber =id.value;
if (idnumber.length<18| | IDNUMBER.LENGTH&GT;19)
{
document.getElementById (id.name). innerhtml= "The length of the ID card number is incorrect";
return false;
}
var expr=/([0]{18}[x|y]?) | ([1]{18}[x|y]?) /I;
if (Expr.test (IDNumber))
{
document.getElementById (id.name). innerhtml= "ID number may not be all ' 0 ' or all ' 1 '";
return false;
}
return true;
}
function Checkphonenumber ()
{
Match input data with regular expressions
var Id=document.getelementbyid ("PhoneNumber");
var phone = Id.value;
Match to a non-numeric character, return false
var expr =/\d/i;
if (expr.test (phone))
{
document.getElementById (id.name). Innerhtml= "Cannot enter non-numeric characters";
return false;
}
return true;

}
function Checkemail ()
{
Match input data with regular expressions
var id = document.getElementById ("EMAIL")
var email = id.value;
To start with a letter or number, followed by an @, alphanumeric ending with. com
var expr =/^ ([0-9]|[ A-z]) +@ ([0-9]|[ A-z]) + (\.[ C][O][M]) $/i;
if (!expr.test (email))
{
document.getElementById (id.name). innerhtml= "Input mailbox format is incorrect";
return false;
}
return true;
}

Css

Copy Code code as follows:

@charset "Utf-8";
/* CSS Document * *
#BODY {
Text-align:center;
}

#TABLE {
Text-align:left;
Margin:auto;
Float:left;
}
#DIV_FORM {
margin-left:300px;
}
#TABLE2 {
Text-align:left;
width:150px;
height:150px;
}
#TABLE2 TR
{
height:24px;
}
#TABLE2 span{
Display:none;
}

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.