Q:

Validate phone number with javascript and regex

I want to validate phone number with javascript, so far i have regex that looks like this: 
/^[0-9\+]{8,13}$/ 
But it is not what i finally wanna get. 
I need get phone number format that is default for my country "Poland". For example few phones formats i need check with regex if user correctly passed them: 321123321, 123-321-123, 123 321 123, 123211212, 12-321-12-12, 12 321 12 12.
Sorry if my question is silly but i have no idea how to understand this regex.

A:

Looks like you are allowing digits spaces and hypens.
Why don't you remove spaces and hyphens and check if rest of them are digits or not.
var str = "123 321 123";
str = str.replace( /\s|-/g, "" );

Now run your own regex on it
"123 321 123".replace( /\s|-/g, "" ).match(/^[0-9\+]{8,13}$/)

Or simply include space and hyphen in the regex
"123 321 123".match(/^[0-9\+\s-]{8,13}$/);

