Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7701357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:57:53+00:00 2026-05-31T22:57:53+00:00

How can you annotate phone number data annotation for phone number validation? Is there

  • 0

How can you annotate phone number data annotation for phone number validation?

Is there way to allow this format in front-end like using HTML5 pattern? I know that there is data type for phone number in both HTML5 and MVC3 but was wondering if we can format that in something like (000)-000-0000 or 000-000-0000 so user can not enter more than 10 digits and if he enters a phone it displays in above formats. I tried this so far:

    [Required]
    [DataType(DataType.PhoneNumber)]
    [RegularExpression(@"^(\d{10})$", ErrorMessage = "Please enter proper phone number.")]
    [Display(Name = "phone")]
    public string Phone { get; set; }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T22:57:54+00:00Added an answer on May 31, 2026 at 10:57 pm

    You might be interested in a jQuery mask plugin.

    http://digitalbush.com/projects/masked-input-plugin/

    Or you could set a .blur on your phone number input that will format the user’s input if there are 10 digits. For instance:

    $("#PhoneNumber").blur(function (event) {
        var phoneNumber = $(this).val();
        // replace all non-numeric characters in phoneNumber
        // do regex check on remaining digits to ensure there are 10 digits
        // if regex passes, format phoneNumber however you like
        %(this).val(phoneNumber);
    });
    

    However, in the second case, you will have to change your regular expression data annotation because formatting the phone number in this way will always fail your current regular expression check. Whatever format you want the user to submit the phone number should be the format of this regular expression validation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Java, we can annotate members like this: @Annotation private Type member; My question
Is there any way that I can use Jackson JSON Views or something like
How can I annotate my model so I can allow only alphabets like A-Z
I have an annotation @MyAnnotation and I can annotate any type (class) with it.
According to the class ElementType in the API, you can annotate local variables and
I can't figure out a use case for being able to annotate interfaces in
If I annotate a method of a class with an attribute, I can then
Can anyone tell me how I can display a status message like 12 seconds
I'm looking for a tool with which I can annotate source code. I have
I have this code in one of my @PersistenceCapable classes: @Persistent private Blob data;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.