Judging the form text box (judging by losing focus)

Source: Internet
Author: User

<! DOCTYPEHtml>
<Htmllang="EN">
<Head>
<Metacharset="UTF-8">
<Title>document</Title>
<Style>
Label {
DisplayInline-block;
Width80px
Text-align:Right
}
span {
ColorRed
}
</Style>
</Head>
<Body>
<P><LabelFor="Username">User name:</Label><InputType="Text"Id="Username"Onblur="Usernameonblur ()"onkeydown="Usernameenterevent (Event"/><SpanId="Usernamewarn"></Span></P>
<P><LabelFor="Password">Password:</Label><InputType="Password"Id="Password"Onblur="Passwordonblur ()"onkeydown="Passwordenterevent (Event"/><SpanId="Passwordwarn"></Span></P>
<P><LabelFor="Repassword">Confirm Password:</Label><InputType="Password"Id="Repassword"Onblur="Repasswordonblur ()"onkeydown="Repasswordenterevent (Event"/><SpanId="Repasswordwarn"></Span></P>
<P><buttononclick="Register ()">Registered</button></P>
</Body>
<Script>
VarUsernameele =Document.getElementById ("username");
VarUsernamewarnele =Document.getElementById ("Usernamewarn");
VarUsernameregexp =/^ (\[email protected]\w+\.\w+) | (1[3458]\d{9}) $/;

VarPasswordele =Document.getElementById ("Password");
VarPasswordwarnele =Document.getElementById ("Passwordwarn");
VarPasswordregexp =/^[0-9a-za-z]{6,12}$/;

VarRepasswordele =Document.getElementById ("Repassword");
var Repasswordwarnele = document.getElementById ("Repasswordwarn"); function Registervalidate () {var count = 0;//Clear all Authentication usernamewarnele.innerhtml = ""; passwordwarnele.innerhtml = ""; repasswordwarnele.innerhtml = ""; Verify user name Count + = Usernamevalidate (); Verify password Count + = Passwordvalidate (); Confirm Password Count + = Repasswordvalidate (); return count = = 0? True:false; }//Register function register () {//verify var flag = Registervalidate (), if (flag) {location.href = "hi.html";} else {alert ("register Failure "); }}//Verify user name function Usernamevalidate () {usernamewarnele.innerhtml = ""; if (Usernameele.value = = "") {usernamewarnele.innerhtml = "username cannot be empty! "; return 1; } else if (!usernameregexp.test (Usernameele.value)) {usernamewarnele.innerhtml = "username can only be mailbox or mobile number! "; return 1; } return 0; }//Verify the Password function passwordvalidate () {passwordwarnele.innerhtml = ""; if (Passwordele.value = = "") {passwordwarnele.innerhtml = "password cannot be empty! "; return 1; } else if (!passwordregexp.test (Passwordele.value)) {passwordwarnele.innerhtml = "Password can only be composed of 6 to 12 digits of English letters or numbers!" "; return 1; } return 0; }//Verify that the password function repasswordvalidate () {repasswordwarnele.innerhtml = ""; if (Repasswordele.value = = "") {repasswordwarnele.innerhtml = "password cannot be empty! "; return 1; } else if (passwordele.value! = repasswordele.value) {repasswordwarnele.innerhtml = "The password entered is inconsistent! "; Console.info (Passwordele.value); return 1; } return 0; }//user name loses focus function Usernameonblur () {//Verify user name Usernamevalidate ();}//user name loses focus function Passwordonblur () {//verify user name Passwo Rdvalidate (); }//user name loses focus function Repasswordonblur () {//Verify user name Repasswordvalidate ();}//User name Carriage return event function usernameenterevent (event) {V Ar eventObj = Event | | window.event; if (Eventobj.keycode = = =) {Passwordele.focus ();}} Password return event function passwordenterevent () {var eventObj = event | | window.event; if (eventobj.keycode = = =) {Repasswordel E.focus (); }}//Password return event function passwordenterevent () {var eventObj = event | | window.event; if (eventobj.keycode = = =) {Repasswo Rdele.focus (); }}</script&Gt;

Determine the form text box (if you lose focus)

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.