I am trying to put in validation for the mobile number entered by the user despite putting in regular expression for 10 digit mobile number.
Here is the Model class
public partial class student1
{
public int StudentId { get; set; }
[Required]
[StringLength(30)]
public string Name { get; set; }
public string Branch { get; set; }
[Display(Name = "Mobile Number:")]
[Required(ErrorMessage = "Mobile Number is required.")]
[RegularExpression("^([07][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] | 8[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] | 9[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9])", ErrorMessage = "Invalid Mobile Number.")]
public Nullable<int> Mobile { get; set; }
}
Create
view
@Html.EditorFor(model => model.Mobile)
@Html.ValidationMessageFor(model => model.Mobile, "", new { @class = "text-danger" })
When I run it, for mobile number entered less than 10 it shows the error message that I had written. But for value 10 and greater I get a new message that says
The value '999999999' is not valid for Mobile Number:.
I don't know where is this message coming from. Also, why isn't it accepting the 10 digit value?