mercredi 2 décembre 2015

Ignoring null values when using Regex Validator in Data Annotation

I'm having an issue with a nullable field with a Regex Format for a Phone Field

Im using ASP.net MVC 3

Here is my Regex Format Validator in my Data Annotation

[Display(Name = "Phone")]
[RegularExpression(@"^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$", ErrorMessage = "Invalid Phone Number")]
public string Phone { get; set; }

My question is, is there a workaround to ignore the field when the value is null and hide the Error Message to it? Thanks

Aucun commentaire:

Enregistrer un commentaire