Regular expression error message
You need to place your message in RegularExpression
attribute, not Required
attribute.
You've added your error message to Required
attribute, which means it will be displayed when the field is empty.
You have assigned the ErrorMessage
to the RequiredAttribute
(which you absolutely don't need in this case because of the regular expression). So:
[Display(Name = "Contact Number")]
[RegularExpression(@"^\d{1,15}$", ErrorMessage = "Please enter up to 15 digits for a contact number")]
public string ContactNumber { get; set; }