Front Desk verification:
First you have to have a parameter class, the parameter class code is as follows
Summary of Validation tokens
[DisplayName ("Email:")]
[Required (errormessage = "Please enter your email")]
[RegularExpression (@ "^ (\w-*\.*) [email protected] (\w-?) + (\.\w{2,}) +$ ", errormessage =" Please enter the correct mailbox ")]
public string Email {get; set;}
And then go back to the view. Validating parameter classes with Validactionmessagefor
<p>
<label id= "Label_mail" for= "mail" > Email </label>
@Html. textboxfor (model = Model.email, new {@class = "user_input", TabIndex = "4"})
@Html. validationmessagefor (model = model.email)
</p>
Background verification: Personally think it is more appropriate to write a validation class,
Validation class:
public bool Isemail (string isemail) {
Regex regchzn = new Regex (@ "^ (\w-*\.*) [email protected] (\w-?) + (\.\w{2,}) +$ ");
Match m = Regchzn.match (Isemail);
return m.success;
}
Call in the controller to determine if validation succeeds:
private bool Validate (Field field)
{
BOOL Isemail=validate. Isemail (Field.email);
if (isemail==true)
{
return true;
}
else{
return false;
}
}
if (modelstate.isvalid)
{
Used to determine whether the front-end verification
if () {//is used here to write back-end validation
}
}
Pure hand, reproduced please show the original link
. Net MVC foreground validation and background validation