Asp.net mvc regex enter

^[a-zA-Z0-9-_. ]*$ for textarea

I want to make available in the following regular expression. How should I do it?

+3
source share
2 answers

Do you want you to allow newlines? This will:

^[a-zA-Z0-9-_. \r\n]*$
+3
source

You can use declarative attributes to accomplish this.

Here's a post to get you started.

Using the provided regular expression, you can do the following in the code modelto make the field mandatory and confirmed by the specified criteria.

[Required(ErrorMessage = "Please enter a value")]
[RegularExpression("^[a-zA-Z0-9-_. ]$", ErrorMessage = "Please enter valid text")]
public string MyTextBox { get; set; }

( ASP.NET MVC), .

0

Source: https://habr.com/ru/post/1770318/


All Articles