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), .