You need to write your own RegularExpressionAttribute ... something like this:
public class DisallowHTMLAttribute : RegularExpressionAttribute
{
public DisallowHTMLAttribute()
: base(@"</?\w+((\s+\w+(\s*=\s*(?:"".*?""|'.*?'|[^'"">\s]+))?)+\s*|\s*)/?>")
{
}
public override string FormatErrorMessage(string name)
{
return String.Format("The field {0} cannot contain html tags", name);
}
}
You must register the adapter to enable client-side validation, so in the Application_Start in Global.asax add this line of code:
DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(DisallowHTMLAttribute), typeof(RegularExpressionAttributeAdapter));
And in your model, add an attribute to the properties that you want to disable html tags, for example:
[DisallowHTML]
public string SomeProperty{ get; set; }