ASP.NET Core 2.2 Phone Attribute won't display validation errors RRS feed

  • Question

  • [Required]
    [Display(Name = "Contact Phone Number")]
    public string Phone { get; set; }

    I am trying to make it so when a user registers on our website, they must input a valid phone number. Should they not, the page will produce an error message that says so. Currently, the only error I got is due to the [Required] tag, saying that "Contact Phone Number is required"

    I am able to produce the desired results using the following line, but I thought that the [Phone] tag would handle this functionality.

    [RegularExpression("^(?!0+$)(\\+\\d{1,3}[- ]?)?(?!0+$)\\d{10,15}$", ErrorMessage = "Please enter a valid phone number")]

    Monday, April 22, 2019 9:33 PM

All replies

  • Hi zshureih,

    Thank you for posting here.

    Since your question is more related to ASP.NET Core, you could post a new thread in ASP.NET Core forum.


    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, April 23, 2019 5:34 AM