JS User Registration Verification Code

Source: Internet
Author: User

Reprint of someone else's ...

This is the code for the Java script script to write user-side registration validation.

The main features are the following: All options are not empty and the user name is 6-16 bits long. Age can only be numbers, and between 18-30. Identification of the identity card.
e-mail must be legal and valid. Hobbies and skills must be checked one!

The following is the code, or that sentence, read to see, do not understand contact me! Haha, huh! **********************

The code includes the JS section and the main part of the page.

<! 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> Untitled Document </title>
<style type= "Text/css" >
<!--
. STYLE2 {font-size:12px}
-
</style>
<style>
. Red
{color: #FF0000;}
Body
{font:12px;}
</style>
<script language= "javascript" type= "Text/javascript" >
function Cname ()
{
var Name=document.getelementbyid ("Tname"). Value;
for (Var i=0;i<name.length;i++)
{
if (Name.charat (i) >= "0" && name.charat (i) <= "9")
{
document.getElementById ("Rname"). style.color= "Red";
document.getElementById ("Rname"). Innerhtml= "username cannot have numbers! ";
return false;
}
}
if (name.length== "")
{
document.getElementById ("Rname"). style.color= "Red";
document.getElementById ("Rname"). innerhtml= "Please enter your user name! ";
return false;
}
else if (name.length<6 | | NAME.LENGTH&GT;16)
{
document.getElementById ("Rname"). style.color= "Red";
document.getElementById ("Rname"). Innerhtml= "User name can only be made up of 6-16-bit characters";
return false;
}
Else
{
document.getElementById ("Rname"). style.color= "Green";
document.getElementById ("Rname"). innerhtml= "This user name can be used";
return true;
}
}
function Cpwd1 ()
{
var Pwd1=document.getelementbyid ("Tpwd1"). Value;
if (pwd1.length== "")
{
document.getElementById ("Rpwd1"). style.color= "Red";
document.getElementById ("Rpwd1"). innerhtml= "Please enter your password!" ";
return false;
}
else if (pwd1.length<6 | | pwd1.length>16)
{
document.getElementById ("Rpwd1"). style.color= "Red";
document.getElementById ("Rpwd1"). Innerhtml= "Passwords can only be made up of 6-16-bit characters";
return false;
}
Else
{
document.getElementById ("Rpwd1"). style.color= "Green";
document.getElementById ("Rpwd1"). Innerhtml= "Password passed";
return true;
}
}
function Cpwd2 ()
{
var Pwd1=document.getelementbyid ("Tpwd1"). Value;
var Pwd2=document.getelementbyid ("Tpwd2"). Value;
if (PWD2!=PWD1)
{
document.getElementById ("Rpwd2"). style.color= "Red";
document.getElementById ("Rpwd2"). Innerhtml= "Please keep the same password as above!" ";
return false;
}
Else
{
document.getElementById ("Rpwd2"). style.color= "Green";
document.getElementById ("Rpwd2"). Innerhtml= "Verify password Passed";
return true;
}
}
function Cid ()
{
var Pid=document.getelementbyid ("Tid"). Value;
if (pid.length== "")
{
document.getElementById ("Rid"). style.color= "Red";
document.getElementById ("Rid"). innerhtml= "Please enter your ID number! ";
return false;
}
else if (pid.length<0 | | pid.length>18)
{
document.getElementById ("Rid"). style.color= "Red";
document.getElementById ("Rid"). Innerhtml= "Now only supports the second generation of 18-bit ID cards";
return false;
}
Else
{
document.getElementById ("Rid"). style.color= "Green";
document.getElementById ("Rid"). innerhtml= "Confirm";
return true;
}
}
function Cemail ()
{
var Email=document.getelementbyid ("Temail"). Value;
if (email.length== "")
{
document.getElementById ("Remail"). style.color= "Red";
document.getElementById ("Remail"). innerhtml= "Please enter your e-mail address! ";
return false;
}
else if (Email.indexof ("@") <1 | | email.indexof (".") <2 | | Email.indexof (".") <email.indexof ("@"))
{
document.getElementById ("Remail"). style.color= "Red";
document.getElementById ("Remail"). Innerhtml= "Please provide legal and valid e-mail address";
return false;
}
Else
{
document.getElementById ("Remail"). style.color= "Green";
document.getElementById ("Remail"). Innerhtml= "format is legal";
return true;
}
}
function Ctel ()
{
var Tel=document.getelementbyid ("Ttel"). Value;
for (Var i=0;i<tel.length;i++)
{
if (Tel.charat (i) < "0" | | Tel.charat (i) > "9")
{
document.getElementById ("Rtel"). style.color= "Red";
document.getElementById ("Rtel"). Innerhtml= "mobile phone number can only be 11 digits! ";
return false;
}
}
if (tel.length== "")
{
document.getElementById ("Rtel"). style.color= "Red";
document.getElementById ("Rtel"). innerhtml= "Please enter your mobile phone number";
return false;
}
else if (tel.length<0 | | TEL.LENGTH&GT;11)
{
document.getElementById ("Rtel"). style.color= "Red";
document.getElementById ("Rtel"). Innerhtml= "mobile phone number only 11 digits, and can only be digital";
return false;
}
Else
{
document.getElementById ("Rtel"). style.color= "Green";
document.getElementById ("Rtel"). Innerhtml= "format is legal";
return true;
}
}
var Team; Variable team, which is used to receive the ID value uploaded by the check box ' Select All ' box
var idname; The ID value of the subkey that is used to receive the ' Select All ' entry for the check box
function CheckBox (team,idname)//functions (parameter one, pass parameter two)
{
var ALT; Determine the value of the ALT attribute
var ID; Gets the value of the variable team
var idname; Get the ID name of the corresponding Div
if (team== "interest")
{
Alt= "like";
Id= "Interest";
Idname= "Rinter";
}
else if (team== "technique")
{
alt= "Tech";
Id= "technique";
Idname= "Rtech";
}
Else
{
Alert ("Error in the value of the pass! Please contact the programmer! ");
}
var Call=document.getelementbyid (ID). checked;
var Bol=false;
if (call)
{
For (Var i=0;i<document. regform.elements.length;i++)
{
if (document. regform.elements[i].type== "checkbox" && document. Regform.elements[i].alt==alt)
{
Document. Regform.elements[i].checked=true;
document.getElementById (idname). style.color= "Green";
document.getElementById (idname). innerhtml= "√";
}
}
}
Else
{
For (Var i=0;i<document. regform.elements.length;i++)
{
if (document. regform.elements[i].type== "checkbox" && document. Regform.elements[i].alt==alt)
{
Document. Regform.elements[i].checked=false;
document.getElementById (idname). style.color= "Red";
document.getElementById (idname). innerhtml= "x Make sure you have selected one! ";
}
}
}
}
function Cinterest ()
{
var Bol=false;
For (Var i=0;i<document. regform.elements.length;i++)
{
if (document. regform.elements[i].type== "checkbox" && document. regform.elements[i].alt== "like" && document. regform.elements[i].checked)
{
document.getElementById ("Rinter"). style.color= "Green";
document.getElementById ("Rinter"). Innerhtml= "√ Pass";
Bol=true;
return true;
}
Else
{
document.getElementById ("Rinter"). style.color= "Red";
document.getElementById ("Rinter"). Innerhtml= "You have not made a choice";
Bol=false;
}
}
if (Bol==false)
{return false;}
}
function Ctechnique ()
{
var Bol=false;
For (Var i=0;i<document. regform.elements.length;i++)
{
if (document. regform.elements[i].type== "checkbox" && document. regform.elements[i].alt== "Tech" && document. regform.elements[i].checked)
{
document.getElementById ("Rtech"). style.color= "Green";
document.getElementById ("Rtech"). Innerhtml= "√ Pass";
Bol=true;
return true;
}
Else
{
document.getElementById ("Rtech"). style.color= "Red";
document.getElementById ("Rtech"). Innerhtml= "You have not made a choice";
Bol=false;
}
}
if (Bol==false)
{return false;}
}

function Result ()
{
if (Cname () && Cpwd1 () && Cpwd2 () && Cid () && cemail () && Ctel () && Cintere St () && Ctechnique ())
{
Alert ("Your profile is filled in correctly!") Please wait for review! ");
}
Else
{
Alert ("Your data has been filled in error");
}
}
</script>
<body><center>
<form name= "Regform" id= "Regform" action= "#" >
<table width= "980" border= "1" cellpadding= "0" cellspacing= "0" >
<tr>
&LT;TD colspan= "3" align= "center" ><span class= "Red" > Welcome to apply for Beijing China New Enterprise Management College teacher job </span></td>
</tr>
<tr>
&LT;TD width= "align=" right "><span class=" Red "> * </span> user name:</td>
&LT;TD width= "349" ><input type= "text" name= "Tname" id= "Tname" onblur= "Cname ()"/></td>
&LT;TD width= "383" align= "left" ><div class= "STYLE2" id= "rname" > Please enter your nickname (6-16 characters) and cannot have a number. </div></td>
</tr>
<tr>
&LT;TD align= "right" ><span class= "Red" > * </span> password:</td>
<td><input type= "Password" name= "Tpwd1" id= "Tpwd1" onblur= "Cpwd1 ()"/></td>
&LT;TD align= "left" ><div class= "STYLE2" id= "RPWD1" > Please enter your password (6-10 characters), can be any character. </div></td>
</tr>
<tr>
&LT;TD align= "right" ><span class= "Red" > * </span> Password confirmation:</td>
<td><input type= "Password" name= "Tpwd2" id= "Tpwd2" onblur= "Cpwd2 ()"/></td>
&LT;TD align= "left" ><div class= "STYLE2" id= "RPWD2" > re-enter the password just now, requiring two passwords to be consistent. </div></td>
</tr>
<tr>
&LT;TD align= "right" ><span class= "Red" > * </span> ID number:</td>
<td><input type= "text" Name= "tid" id= "tid" onblur= "Cid ()"/></td>
&LT;TD align= "left" ><div class= "STYLE2" id= "Rid" > Please enter your ID number (18 second-generation ID)! </div></td>
</tr>
<tr>
&LT;TD align= "right" ><span class= "Red" > * </span> e-mail address:</td>
<td><input type= "text" name= "Temail" id= "Temail" onblur= "Cemail ()"/></td>
&LT;TD align= "left" ><div class= "STYLE2" id= "Remail" > Please provide a valid e-mail address. </div></td>
</tr>
<tr>
&LT;TD align= "right" ><span class= "Red" > * </span> Mobile:</td>
<td><input type= "text" name= "Ttel" id= "Ttel" onblur= "Ctel ()"/></td>
&LT;TD align= "left" ><div class= "STYLE2" id= "Rtel" > Please enter your phone number </div></td>
</tr>
<tr>
&LT;TD align= "right" ><span class= "Red" > * </span> Your hobbies:</td>
<td>
<input type= "checkbox" name= "interest" id= "interest" onclick= "checkbox (' interest ', ' rinter ')"/> Select all
<input type= "checkbox" alt= "like" name= "shopping" id= "shopping" onclick= "cinterest ()"/> Shopping
<input type= "checkbox" alt= "like" name= "Sing" id= "Sing" onclick= "Cinterest ()"/> Singing
<input type= "checkbox" alt= "like" name= "Game" id= "Game" onclick= "Cinterest ()"/> Play games
<input type= "checkbox" alt= "like" name= "Books" id= "book" onclick= "Cinterest ()"/> Reading </td>
&LT;TD align= "left" ><div class= "STYLE2" id= "Rinter" > Please select at least one </div></td>
</tr>
<tr>
&LT;TD align= "right" ><span class= "Red" > * </span> technology you are good at:</td>
<td>
<input type= "checkbox" name= "technique" id= "technique" onclick= "checkbox (' technique ', ' rtech ')"/> Select all
<input type= "checkbox" alt= "Tech" Name= "java" id= "java" onclick= "Ctechnique ()"/>java language
<input type= "checkbox" alt= "Tech" name= ". Net" id= ". Net" onclick= "Ctechnique ()"/&GT;. NET language
<input type= "checkbox" alt= "Tech" name= "website" id= "website" onclick= "Ctechnique ()"/> Website production Development
<input type= "checkbox" alt= "Tech" name= "Web" id= "Web" onclick= "Ctechnique ()"/> Network </td>
&LT;TD align= "left" ><div class= "STYLE2" id= "Rtech" > Please select at least one </div></td>
</tr>
<tr>
&LT;TD align= "right" ><span class= "Red" > * </span> Classes you plan to teach:</td>
<td>
<select name= "College" id= "College" Onchange= "Show ()" ></select><select name= "Clas" id= "Clas" >< option>--Please select--</option></select>
<td> </tr>
<tr>
&LT;TD colspan= "3" align= "center" ><input type= "button" Name= "STB" id= "STB" value= "Submit" onclick= "Result ()"/> <input type= "Reset" name= "res" id= "res" value= "refill"/></td>
</tr>
</table>
</form>
</center></body>
<script>
var col=new Array ("--Please select--", "Computer Academy", "Art and Design Institute", "Business School");
col["--Please Choose--"]=["--Please select the Institute--"];
col["Computer Academy"]=["JAVA", ". NET", "Web Development", "Network Maintenance"];
Col["School of Art and Design"]=["digital media", "creative design";
col["Business School"]=["e-commerce", "Entrepreneurial class", "Investment and finance";

for (Var i=0;i<col.length;i++)
{
var newopt=new Option (Col[i],col[i]);
Document. Regform.college.options.add (newopt);
}
var Newcla;
var Discla;
Function Show ()
{
Document.  regform.clas.length=0; Empty the contents of the second SEL option
Newcla=document. Regform.college.value; Get the value in the first SEL option
Loop, write.
for (Var i in COL[NEWCLA])
{
Discla=new Option (Col[newcla][i],col[newcla][i]); Assigning a variable to a new option value
Document.   Regform.clas.options.add (DISCLA); Writes the acquired options value to the SEL option
}
}

</script>

JS User Registration Verification Code

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.