here my code:
@using (Html.BeginForm("Register", "User", FormMethod.Post, new { id = "RegisterForm" }))
{
@Html.TextBoxFor(m => m.EmailAddress,
new { size = "40",
@onchange = "UserNameVal();",
@tabindex = "1" })
}
$("#RegisterForm").validate({
rules: {
EmailAddress: {
required: true
}
},
messages: {
EmailAddress: {
required: "<br/> Please enter the Email address"
}
}
});
if ($("#RegisterForm").valid()) {
$("#RegisterForm").submit();
}
Why don't you use annotation to validate the fields? it's much easier and cleaner, you can do as below:
public class MyModel
{
[Required(ErrorMessage = "Please enter the Email address")]
public string Email { get; set; }
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.