0

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.

10
  • it is ok but i need something more What is something more? Commented Sep 30, 2016 at 13:41
  • @bub look under text you quoted Commented Sep 30, 2016 at 13:43
  • 2
    Or this or insert one of the tons of duplicates here Commented Sep 30, 2016 at 13:43
  • @mdziekon nope i need regex to look something difrent but dunno how to make it. Commented Sep 30, 2016 at 13:43
  • @kuchar I don't see anything! Commented Sep 30, 2016 at 13:51

2 Answers 2

3

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}$/);
Sign up to request clarification or add additional context in comments.

Comments

0

Use below regex which will allow - and blank space and all the characters should be between 8 and 13.

^[0-9\s- \+]{8,13}$

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.