Regular Expressions 101

Community Patterns

Regex for minimum specific character length


Regular Expression
ECMAScript (JavaScript)

^([+]([0-9 ]{8,19}))$


Hi All,

I'm currently having an issue regarding writing regex to check minimum length of specific character. My case is for phone number. E.g.

Phone number required at leat 8 character and max 19 character. However, people are allowed to write with 'space' character in between and that 'space' shouldn't be counted.

This is my regex so far :

^([+]([0-9 ]{8,19}))$

The problem with it is, if i put 'space' character 8 times, it will consider as valid, which it shouldn't. Is there anyway to do this in Regex?

Much appreaciated the feedback for this!

Submitted by krisha - 10 years ago