I’m working on ASP.NET MVC 4. I’m using Data Annotations in model for validation.
There is one field name Mobile and validating using regular expression like below.
[RegularExpression(@"[0-9]{10}", ErrorMessage = "Mobile Number is Not Valid")]
public string Mobile { get; set; }
As per the application requirement above field is not mandatory but need to validate Mobile number if user insert it.
My problem is that when I submit form it displays “Mobile field is required.” but the mobile field is not decorate with [Required] attribute. So How it display as required?
What could be the reason?
How to solve it?
You can do it very easily using following simple jQuery..
Pls try and let me us know if that works for you or not.
Thanks