How can i check for opening and closing brackets in regex

How can i check for opening and closing brackets in regex
0

#1

Hi,

I have been trying to solve - https://www.freecodecamp.org/challenges/validate-us-telephone-numbers

Now i have read and searched but could not find any regex where i can check if there is any opening bracket then only there can be a closing bracket, i have been stuck on this point for some time now , can any one guide me here … thanks …below is my code -


function telephoneCheck(str) {
  var test1 = /\d?\s?\(?\d{3}\-?\)?\s?\d{3}?-?\s?\d{4}/;
  return test1.test(str);
}



telephoneCheck("1 555)555-5555");

#2

You could check for the bracketed and the non-bracketed part and use | to match either of them.

(\d{3}|\(\d{3}\))

#3

@kevcomedia - thank you so much …do yo u have any channel for javascript ?


#4

What do you mean by channel for javascript?


#5

Like a youtube channel


#6

No, sorry. I can’t imagine myself having a youtube channel :fearful:. Not with my awkward stuttering voice :sweat_smile:

I’m trying to write what I learn though, but I don’t have much written for now


#7

This was really helpful. Thank you!