-3

I need to have a regular expression to restrict the number of digits in a string which may contain alphabets or any other characters along with digits. Is this possible with regular expressions ?

Alan Moore
  • 73,866
  • 12
  • 100
  • 156
Ravindra
  • 95
  • 2
  • 10

1 Answers1

0

The idea is to anchor beginning and end of string and allow exactly n repetitions of a digit with something else. For example, exactly 6 digits in a string:

^\D*(\d\D*){6}$
Amadan
  • 191,408
  • 23
  • 240
  • 301