There is a need for client unobtrusive validation on the textbox to warn user that he types invalid symbols. I want to use RegularExpression in data annotation, somethimg like this:
[Required]
[Display(Name = "RecordBody", ResourceType = typeof(Resources))]
[RegularExpression(@"(\<(/?[^\>]+)\>)", ErrorMessageResourceType = typeof(ValidationErrors), ErrorMessageResourceName = "DisallowHtml")]
[StringLength(8191, ErrorMessageResourceType = typeof(ValidationErrors), ErrorMessageResourceName = "TooLongEntry")]
public string Description { get; set; }
A regular expression is used on server side to validate user input and is used on client side in Javascript regular expression:
<textarea cols="20" data-val="true" data-val-disallowhtml="Поле Текст записи содержит недопустимые символы" data-val-disallowhtml-pattern="(\<(/?[^\>]+)\>)" data-val-length="Введено слишком много символов. Допустимо: 8191" data-val-length-max="8191" data-val-required="Требуется поле Текст записи." id="Description" name="Description" rows="2"></textarea>
(\<(/?[^\>]+)\>)
doesn't work because it matches only html tags. I need a regex that matches all content that is not an HTML tag. In other words to negate the whole regex.
Here is a working example http://cafuego.net/2011/11/15/html-and-regular-expressions. But i suppose (?<=^|>)([^><]+?)(?=<|$)
it works only in php.
text text
- valid.text text <b> text </b>
- invalid and user is warned he typed invalid signs – olly