Original to http://www.itivy.com/ivy/archive/2011/2/20/634338371453673322.html
User Registration is a very widely used module. I don't know if you have ever encountered such a website. You have to submit a form and fill in many items. When the result is submitted, the page is refreshed, then you are prompted that the user name has been
There are errors such as incorrect verification codes. when you look back, you have to fill in many items in the form again, which is annoying. If there is a way for you to verify that each item meets system requirements before submitting the form, you can use
Users save a lot of time, and the user experience is improved by hitting.
Next, I will introduce an automatic form verification plug-in formvalidator, which provides beautiful verification result prompts, scalable Regular Expression support, Ajax verification support, and custom verification solutions. Let's take a look at the general results. The article will also provide a demo for your reference.
Introduce the main script and style file of the formvalidator plug-in to the HTML file. Because it is based on jquery, do not forget to introduce the main library script of jquery:
<link type="text/css" rel="stylesheet" href="/Scripts/FormValidator/style/validator.css" /><link type="text/css" rel="stylesheet" href="/Scripts/css.css" /><script type="text/javascript" src="/Scripts/jquery-1.4.1.min.js"></script><script type="text/javascript" src="/Scripts/FormValidator/formValidator.js"></script>
Enter the email address and nickname in the HTML code:
<Form ID = "registerform" Action = "/submitresult. aspx "method =" Post "> <Div class =" Block tip "> <SPAN class =" pre_tip "> registered email: </span> <input type = "text" id = "txtemail" name = "txtemail" class = "input_text"/> <span id = "txtemailtip" class = "fv_tip" style = "width: 280px "> </span> </div> <Div class =" Block tip "> <SPAN class =" pre_tip "> registered nickname: </span> <input type = "text" id = "txtname" name = "txtname" class = "input_text"/> <span id = "txtnametip" class = "fv_tip" style = "width: 280px "> </span> </div> <input type =" Submit "value =" Submit "class =" input_btn "style =" margin-left: 50px "/> </form>
Verify the JS Code of the email address and nickname format:
<SCRIPT type = "text/JavaScript"> $ (document ). ready (function () {$. formvalidator. initconfig ({formid: "registerform", onerror: function (MSG) {}, onsuccess: function () {}}); // initialization, not less $ ("# txtemail "). formvalidator ({onshow: "", onfocus: "used to retrieve the password, must be true and valid", oncorrect: "correct "}). inputvalidator ({min: 2, Max: 100, onerror: "the email you entered is invalid. Please confirm "}). regexvalidator ({Regexp: "^ ([\ W-.] +) @ ([0-9] {1, 3 }. [0-9] {1, 3 }. [0-9] {1, 3 }.) | ([\ W-] + .) +) ([A-Za-Z] {2, 4} | [0-9] {1, 3}) (]?) $ ", Onerror:" The email format you entered is incorrect "}). ajaxvalidator ({type: "Post", URL: "/Ajax. ashx ", datatype:" text/plain ", success: function (data) {If (Data =" 1 ") return true; else {This. onerror = data; return false }}, error: function () {alert ("the server has not returned data. The server may be busy. Please try again") ;}, buttons: $ ("# btnregister"), onwait: "verifying the validity of the registered email address. Please wait... "}); $ (" # txtname "). formvalidator ({onshow: "", onfocus: "The nickname must be 2-16 Chinese characters, numbers, letters, and underscores", oncorrect: "correct "}). inputvalidator ({min: 2, Max: 16, onerror: "The length of the nickname is 2-16. Please confirm "}). regexvalidator ({Regexp: "^ [\ u4e00-\ u9fa5 \ uf900-\ ufa2d-\ W] + $", onerror: "The nickname must be 2-16 Chinese characters, numbers, letters, and underscores"});}) </SCRIPT>
Now the automatic form is so simple. The following is a demo for your reference.