1 <!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd ">2 <HTMLxmlns= "http://www.w3.org/1999/xhtml">3 <Head>4 <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" />5 <title>Regular expressions for form validation</title>6 7 </Head>8 9 <Body>Ten One <fieldsetstyle= "width:400px;"> A <legend>XXX website Registration</legend> - - <Table> the <TR> - <TD>User name:</TD> - <TD><inputtype= "text"ID= "User"/><span></span></TD> - </TR> + <TR> - <TD>Password:</TD> + <TD><inputtype= "Password"ID= "pwd"onblur= "Pwdblur ()"onfocus= "Pwdfocus ()"/><span></span></TD> A </TR> at <TR> - <TD>Confirm Password:</TD> - <TD><inputtype= "Password"ID= "Repwd"/><span></span></TD> - </TR> - <TR> - <TD>Mailbox:</TD> in <TD><inputtype= "text"ID= "Email"/><span></span></TD> - </TR> to <TR> + <TD><inputtype= "Submit"value= "Register"/></TD> - <TD><inputtype= "Reset"value= "Reset"/></TD> the </TR> * $ </Table>Panax Notoginseng - </fieldset> the + <Scripttype= "Text/javascript"> A functionPwdfocus () { the + varpwd=document.getElementById ("pwd"); - Pwd.style.border="1px Blue Solid"; $ Pwd.nextSibling.innerHTML="Password length must be 6 to"; $ } - functionPwdblur () { - varpwd=document.getElementById ("pwd"); the //get the Value property 1 - //var pwdval=pwd.getattribute ("value");Wuyi the //Get the Value property 2 - varPwdval=Pwd.value; Wu varReg=/^[a-za-z0-9]{6,12}$/; - if(Reg.test (pwdval)==false){ About Pwd.style.border="1px Red Solid"; $ Pwd.nextSibling.innerHTML="Password length must be 6 to"; - }Else{ - Pwd.style.border="1px Green Solid"; - Pwd.nextSibling.innerHTML="Password Available"; A } + the } - </Script> $ </Body> the </HTML>
7, JS using regular expression validation