I am looking to create a form where users can input their phone number and have the flexibility to choose how they want to separate the numbers. I have been using a regex pattern for validation:
var regex = /[^0-9 \/-\\\(\)\+]/;
While this regex works in most cases, there are situations such as @
, :
, and ;
where it doesn't behave as expected. Any suggestions on how to improve this?
Here is an example to illustrate the issue.
testvar = '123@213';
var regex = /[^0-9 \/-\\\(\)\+]/;
if(regex.test(testvar) === true)
{ alert('Chars out of regex-range found'); } // won't fire!