Limit the length of phone number

To limit a phone number to exactly 10 digits using regular expressions (regex), you can use the following pattern:

^\d{10}$

Explanation of the pattern:

  • ^: Asserts the start of the string.
  • \d: Matches any digit (0-9).
  • {10}: Specifies that exactly 10 occurrences of the preceding \d should be matched.
  • $: Asserts the end of the string.

Combined, the pattern ^\d{10}$ ensures that the entire string contains exactly 10 digits and nothing else.