Asp. Mvc 2.0 user client verification example (3), asp. mvc instance description
I will explain ASP to you today.. NET mvc client verification. in general, most of the input content on the page needs to be verified by the client. Generally, JS is used for client verification. Here we will explain how to use jquery. the validate plug-in performs client verification.
First, let's look at the verification results on the betting album page.
The above verification mainly includes
1. the user name cannot be blank
2. The password cannot be blank, and the password length cannot be less than 5 digits
3. confirm that the password cannot be blank. Make sure that the password length cannot be less than five characters. confirm that the password must be consistent with the password entered in the text box.
4. the email address format must be correct.
The following describes how to use the jquery. validate plug-in.Verification Code
[Html] <% @ Page Language = "C #" Inherits = "System. Web. Mvc. ViewPage <MvcLogin. Models. RegisterModel>" %> <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN "" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <Html xmlns =" http://www.w3.org/1999/xhtml "> <Head runat =" server "> <title> registration page </title> <script type =" text/javascript "src = ".. /.. /Scripts/jquery-1.4.1-vsdoc.js "> </script> <script type =" text/javascript "src = ".. /.. /Scripts/jquery. validate. js "> </script> <script type =" text/javascript "> $ (). ready (function () {$ ("# form1 "). validate ({rules: {UserName: {required: true}, UserPwd: {required: true, minlength: 6}, ConfirPwd: {required: true, m Inlength: 6, failed to: "# UserPwd"}, Email: {email: true }}, messages: {UserName: {required: "<span style = 'color: red'> the user name cannot be blank! </Span> "}, UserPwd: {required:" <span style = 'color: red'> the password cannot be blank! </Span> ", minlength: jQuery. format (" <span style = 'color: red'> the password length cannot be less than {0} characters! </Span> ")}, ConfirPwd: {required:" <span style = 'color: red'> confirm that the password cannot be blank! <Span> ", minlength: jQuery. format (" confirm that the password length cannot be less than {0} characters! "), Failed to:" <span style = 'color: red'> the two passwords are inconsistent! </Span> "}, Email: {email:" <span style = 'color: red'> Incorrect Email format! </Span> "}}, onkeyup: false });}); </script>
$ ("# Form1"). validate mainly includes rule rules and message.
For example
rules: { UserName: { required:true },}
The input content in the text box with ID UserName cannot be blank.
Messages: {UserName: {required: "<span style = 'color: red'> Use®? User name? No? Can you leave a blank ?! </Span> "},
If the text box with ID UserName is empty, a prompt is displayed.
The above is the whole process of client verification using the jquery. validate plug-in. I hope it will be helpful for everyone.