0
[Required(ErrorMessage = "You need to add your phone number")]     
public string PhoneNumber { get; set; }

I want to allow numbers only and display error message if it's not a number. I also want to limit it to only 10 digits. How exactly can I do that? Thanks

3
  • You are asking multiple questions: showing an error message is not related to checking the user input. You are also expected to search on your own and show what code or strategy you have come up with. Please read stackoverflow.com/help/how-to-ask Commented Jul 14, 2018 at 9:54
  • I know, i just showed how my current code looks like , and then i explained what i wanted to add. I did some google research but came up with confusing stuff like "regex", didn't really understand formatting or anything so i decided to ask here. Commented Jul 14, 2018 at 10:03
  • Use a [RegularExpression] attribute. Commented Jul 15, 2018 at 0:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.