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 ?
Asked
Active
Viewed 200 times
1 Answers
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