-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
  • 68,531
  • 11
  • 88
  • 149
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
  • 169,219
  • 18
  • 195
  • 256