Telephone number validation

Tell us what’s happening:
the code isnt sufficient to validate all cases , what can i do to make it work?

Your code so far


function telephoneCheck(str) {
var phoneNo = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;
return phoneNo.test(str);
}


console.log(telephoneCheck("1 456 789 4444"));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36.

Challenge: Telephone Number Validator

Link to the challenge:

Where in your code are you checking for a 1 before the 3 digit area code?

Hi,

I think you missed the (?:\d+ )? at the beginning of your expression. It allow you to match the number 1 (without capture group).
This would give something like ^(?:\d+ )?\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$

You can improve your expression here if you want : https://regex101.com/r/MF3zTM/1

Tell us what’s happening:

my regex isnt working still. i have had to use other codes but still nothing
Your code so far*


function telephoneCheck(str) {
var phoneNo = /^\s*(?:\+?(\d{1,3}))?([-.(]*(\d{3})[-.)]*)?((\d{3})[-.]*(\d{2,4})(?:[-.x]*(\d+))?)\s*$/gm
return phoneNo.test(str);
}


console.log(telephoneCheck("1 456 789 4444"));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36.

Challenge: Telephone Number Validator

Link to the challenge:

As far as i can tell, the simpler the better! :slight_smile:
Consider to abstract and write down the requirements^^
Some example:

  • You have always at least 10 number, optionally preceeded by a 1
  • Numbers, when splitted, are always splitted this way: (1) 3-3-4
  • If 1 is present, it is always at the start, alone
  • Separators can be round parenthesys, dashes, spaces, or nothing.

I didn’t tried the points above, consider them just as practice example^^
Good luck!

i have tried some of the suggestions and some i dont know how to go about them.
i am stuck on these excercise. :slightly_frowning_face:

function telephoneCheck(str) {
  
var phoneNo =/^([+]?1[\s]?)?((?:[(](?:[2-9]1[02-9|[2-9][02-8][0-9])[)][\s]?)|(?:(?:[2-9]1[02-9]|[2-9][02-8][0-9])[)][\s]?)|(?:(?:[2-9]1[02-9]|[2-9][02-8][0-9])[\s.-]?)){1}([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2}[\s.-]?){1}([0-9]{4}){1}$/
  return phoneNo.test(str);
  
  }
```console.log(telephoneCheck("1 456 789 4444"));