I need regex to check if a string contains 8 decimal digits or more. It can contain anything else and the digits don't have to be consecutive.
Thanks in advance
EDIT: replaced "number" by "decimal digit" to match accepted answer.
I need regex to check if a string contains 8 decimal digits or more. It can contain anything else and the digits don't have to be consecutive.
Thanks in advance
EDIT: replaced "number" by "decimal digit" to match accepted answer.
/([^\d]*\d){8}/
Perhaps not the most elegant / efficient way to do it, but it works. Basically it will match eight decimals (optionally, with non-decimals between them). If there are more than eight, it will match too.
EDIT
As @Tomalak has pointed out, [^\d]
equals \D
by definition:
/(\D*\d){8}/
/(?:\d+\D+){7,}\d+/
This will match at least 8 numbers with something other than numbers in between.