Regex to check if there are at least x number of digits in a phone number string

Posted written by Paul Seal on October 30, 2020 Regex

At work today I had an interesting problem to solve. I needed to validate a phone number field with a regex and without caring about the format of the phone number.

The client just wanted there to be at least 6 numbers in the phone number field. So on our stand up zoom call I asked for help and my boss came up with this regex which works a treat.

I've shared it here in case anyone else is looking for something similar.

^.*\d.*\d.*\d.*\d.*\d.*\d.*$

It's as simple as that. I was then able to use it in Umbraco Forms on phone number text fields.

If you want to increase the amount of numbers you are looking for, just add another *\d.