Form Verification: Verify that the user input is valid before the form is submitted.
Note: You are prompted to use the text box to clear the reset button at a time. You do not need to reset the message by yourself.
Checkform. js
// Enter function input (msgid) {var MSG = document. getelementbyid (msgid); MSG. classname = 'inputtip '; If (msgid = "msg_username") {MSG. value = "User Name 6 ~ It must start with an 18-digit letter and only contain letters, numbers, and _ ";} If (msgid =" msg_pwd ") {msg. value =" 6 ~ 18 characters, only including letters, numbers, _ ";} If (msgid =" msg_repwd ") {MSG. value = "must be the same as the above password";} If (msgid = "msg_email") {MSG. value = "supports most mailboxes in China";} If (msgid = "msg_qq") {MSG. value = "Enter the real QQ number";}/** display prompt value: input string REG: Regular Expression MSG: Message Display object */function showmsg (value, Reg, MSG) {If (value = "") {MSG. classname = "errortip"; MSG. value = "× cannot be blank! "; Return false;} else if (Reg. test (value) {MSG. classname = "oktip"; MSG. value = "√"; return true;} else {MSG. classname = "errortip"; MSG. value = "× incorrect format! "; Return false ;}} var username_bool = false; var pwd_bool = false; var repwd_bool = false; var email_bool = false; var qq_bool = false; // check whether the user name is valid function checkusername (OBJ, msgid) {var username = obj. value; var MSG = document. getelementbyid (msgid); var Reg =/^ [A-Za-Z] \ W {5, 17} $/; return username_bool = showmsg (username, Reg, MSG );} // check whether the password is valid function checkpwd (OBJ, msgid) {var Pwd = obj. value; var MSG = document. getelementbyid (msgid); V Ar Reg =/^ \ W {6, 18} $/; return pwd_bool = showmsg (PWD, Reg, MSG);} function checkrepwd (OBJ, msgid) {var Pwd = document. forms ['regist']. elements ['pwd']. value; var repwd = obj. value; var MSG = document. getelementbyid (msgid); If (pwd_bool) {If (repwd = "") {MSG. classname = "errortip"; MSG. innerhtml = "× the user name cannot be blank! "; Return repwd_bool = false;} else if (repwd = PWD) {MSG. classname = "oktip"; MSG. innerhtml = "√"; return repwd_bool = true} else {MSG. classname = "errortip"; MSG. innerhtml = "X two passwords are different! "; Return repwd_bool = false;} // email [email protected]. govfunction checkemail (OBJ, msgid) {var email = obj. value; var MSG = document. getelementbyid (msgid); var Reg =/^ \ [email protected] \ W + (\. \ W +) + $/; return email_bool = showmsg (email, Reg, MSG);} function checkqq (OBJ, msgid) {var QQ = obj. value; var MSG = document. getelementbyid (msgid); var Reg =/^ \ D {6, 12} $/; return qq_bool = showmsg (QQ, Reg, MSG);} function checkall () {return username_bool & pwd_bool & repwd_bool & email_bool & qq_bool;} function myreset () {username_bool = false; pwd_bool = false; repwd_bool = false; qq_bool = false ;}
Form.html
<HTML>