ASP NET MVC5 web application, NET 4.6.1
Razor view:
@Html.EditorFor(model => model.message, new { htmlAttributes = new { @class = "form-control textarea", rows = "15", placeholder = Resources.field_required } })
@Html.ValidationMessageFor(model => model.message, "", new { @class = "text-danger" })
ViewModel:
[DataType(DataType.MultilineText)]
[Required(ErrorMessageResourceType = typeof(Resources), ErrorMessageResourceName = "messagevalidation")]
[RegularExpression(@"^[?!,;.\p{L}0-9'-'\s]*$", ErrorMessage = "Please enter letters and numbers only")]
By using implemented regex
^[?!,;.\p{L}0-9'-'\s]*$
or
^[?!,;.'-'\p{L}\d\s]*$
I am able to validate every Unicode alphabet and digit plus a basic set of punctuation marks, which is what I need, in many different regex testing sites (http://regexstorm.net for instance). Nevertheless, running the application, form fails on any input character while I had no problems with previous regex
^[?!,;.A-zÀ-ÿ0-9'-'\s]*$
but it did not validate Unicode (Cyrillic, Chinese, etc...)