2
Answers

how to set min 10 number for mobile number validation?

Mani Kandan

Mani Kandan

7y
238
1
I am using this regular expression for mobile number,
  1. [Required(ErrorMessage = "Required")]  
  2.        [DataType(DataType.PhoneNumber)]  
  3.        [RegularExpression(@"^[\+\d]+(?:[\d-.\s()]*)$", ErrorMessage = "Not a valid Mobile number")]  
  4.        public string MobileNumbers { getset; } 
 But not happening validation when enter less than 10 min number.
And for email validation, 
  1. [Required(ErrorMessage = "Required")]  
  2.        [EmailAddress(ErrorMessage = "Invalid Email Address")]  
  3.        public string EmailIDs { getset; } 
But this is not working when enter look like this,
 
 How can I solve this issues? please help me...
Answers (2)
1
Samatha Reddy

Samatha Reddy

NA 127 7 7y
Hi...
 
Please try this links for phone number
 
http://stackoverflow.com/questions/22378736/regex-for-mobile-number-validation 
 
http://stackoverflow.com/questions/4685500/regular-expression-for-10-digit-number-without-any-special-characters
 
http://stackoverflow.com/questions/25286239/matching-exactly-10-digits-in-javascript 
 
For Email address
 
http://stackoverflow.com/questions/8989081/email-model-validation-with-dataannotations-and-datatype
http://stackoverflow.com/questions/39809439/asp-net-mvc-data-annotation-validator-for-email-or-phone 
Accepted
0
Ramesh Palanivel

Ramesh Palanivel

NA 9.5k 138.6k 7y
Hi Abhilash,
 
Try this code,
 
  1. [Required(ErrorMessage = "Name is required.")]  
  2. [StringLength(40, ErrorMessage = "Name cannot be longer than 40 characters.")]  
  3. public string Name { getset; }