^[a-zA-Z0-9-_. ]*$ for textarea
I want to make available the enter as well in the following regular expression. How would I do that?
^[a-zA-Z0-9-_. ]*$ for textarea
I want to make available the enter as well in the following regular expression. How would I do that?
You can use declarative attributes to accomplish this.
Here's a post to get you started.
Using your provided regular expression, you could do the following in your model
code to make a field both required and validated against a specified criteria.
[Required(ErrorMessage = "Please enter a value")]
[RegularExpression("^[a-zA-Z0-9-_. ]$", ErrorMessage = "Please enter valid text")]
public string MyTextBox { get; set; }
If you are interested in learning more about attributes (not necessarily with respect to ASP .NET MVC) you can check out this article for further reading.
Do you mean that you want to allow newline characters? That would be:
^[a-zA-Z0-9-_. \r\n]*$