I want to do a regex pattren in JavaScript that will allow a string only with numbers and this signs: ()+ and a space. In a length of 5-16 chars.
Please Note: the order of the chars in the string is not important.
What is the right pattren for this?
Thanks
How about this:
It’s quite easy to construct it by yourself. )
First, as you impose strict limits, you should check the whole string, so regex should be wrapped into
/^...$/.Second, if you only need some specific characters, you should use character class: write all them down into […] form. In your case you can shortcut: replace
/^[0123456789 ()+]$/with just/^[0-9 ()+]$/.Finally, state some quantitative limits with {$min, $max} form: in your case that would be
{5,16}. Mix this into what you got so far – and voila! You solved the task. )