Form Verification example

Source: Internet
Author: User

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> 


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.