Reputation: 121
I need to validate all the Indian mobile number using data annotation. in my model i use following code
[Required]
[Display(Name = "Mobile Number")]
[CustomRemote("IsMobileNoAvailable", "Employees",
ErrorMessage = "Mobile No already in use", AdditionalFields = "Id")]
[?]
public string ContactNumber { get; set; }
but i am confuse what i need to write in place of [?] ? Please suggest me the best way to validate mobile number.
Upvotes: 0
Views: 8497
Reputation:
Try this one hope it will help you.
[RegularExpression(@"^([0]|\+91[\-\s]?)?[789]\d{9}$", ErrorMessage = "Entered Mobile No is not valid.")]
Upvotes: 5
Reputation: 15923
You can add this regex in place of [?]
[RegularExpression(@"^((\+91-?)|0)?[0-9]{10}$", ErrorMessage = "Entered phone format is not valid.")]
Upvotes: 4