you can use something like this (i've used for email validation)
[Required(ErrorMessageResourceType = typeof(CCSModelResources), ErrorMessageResourceName = "ANTCommonTextRequiredMessage")]
[RegularExpression(@"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$",
ErrorMessageResourceType = typeof(CCSModelResources), ErrorMessageResourceName = "ANTCommonTextRegularExpressionMessage")]
public new string EmailAddress
{
get { return base.EmailAddress; }
set { base.EmailAddress = value; }
}
and you controller code like
[Authorize]
[HttpPost]
public ActionResult UpdatePersonalDetails(FormCollection form)
{
regUserWizard.PersonalDetails = new MVCPersonalDetails();
if (!TryUpdateModel<MVCPersonalDetails>(regUserWizard.PersonalDetails, form.ToValueProvider()))
{
return View("UpdateUser", regUserWizard);
}
else
{
//you code
}
return RedirectToAction("Index", "Home");
}
you view code like
< %= Html.ValidationSummary("Account creation was unsuccessful. Please correct the errors and try again.") %> <% Html.EnableClientValidation();
using (Html.BeginForm()) { %>
//you code