Today to explain the next asp.net MVC client-side validation. Usually, we in the page for the input of the content to be client-side validation, client-side validation generally use JS, here we explain the use of Jquery.validate plug-ins for client authentication.
First let's look at the verification effect of the registration page
The above verification mainly includes
1. User name cannot be empty
2. Password can not be null, password length can not be less than 5 digits
3. Confirm password cannot be blank, Confirm password length cannot be less than 5 digits, confirm password must and password text box enter consistent
4. The mailbox format must be correct.
The following code is validated using the Jquery.validate plug-in
[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
">
$ ("#form1"). Validate mainly includes rule rules and hint information messages two parts.
For example
Rules:
{
UserName:
{
required:true
},
}
Indicates that the text box entered with ID username cannot be empty.
Messages:
{
UserName:
{
required: "<span style= ' color:red ' >" ¡ì name?) ¨¹ to be a null? </span> "
},
Indicates the contents of a text box with an ID of username if empty, give a hint.
The above is the use of Jquery.validate plug-ins for client-side verification of the whole process, I hope to help you learn.