Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex for more than 10 digits in a mixed string? [duplicate]

Tags:

regex

I need to check for users that are putting their id in the wrong input box.

They might enter the id as 123-456-789-012 or 123456789012 or some variation so I can't just check for digits. The length of the id varies slightly per user, but is always more than 10 digits.

Valid input is a mix of characters and 0-10 digits.

I've seen a lot of solutions for plain digits, but not mixed text. I tried variations of

(\D*\d){0,10}

but that didn't work.

like image 999
thchaver Avatar asked Jul 25 '18 21:07

thchaver


Video Answer


1 Answers

You want "0-n non-digits" then "1-10 lots of a digit-and-any-non-digits":

^\D*(\d\D*){1,10}$
like image 56
Bohemian Avatar answered Sep 22 '22 04:09

Bohemian