Skip to content

Instantly share code, notes, and snippets.

@dcortesnet
Last active February 14, 2023 12:40
Show Gist options
  • Select an option

  • Save dcortesnet/271145ba70f89277a8289ca9f64e1f14 to your computer and use it in GitHub Desktop.

Select an option

Save dcortesnet/271145ba70f89277a8289ca9f64e1f14 to your computer and use it in GitHub Desktop.
Javascript valiación número tel eeuu
// ^\([0-9]{3}\)[0-9]{3}-[0-9]{4}$
function isEEUUPhoneNumber(number) {
const reg = /[-+]?(?:\d{1,2}\s)?\(*(?:\d{3})(?:-|\)|\)\s|\s)*\d{3}(?:-|\s)*\d{4}/;
return reg.test(number);
}
console.log(isEEUUPhoneNumber("1(555)555-5555")); // true
console.log(isEEUUPhoneNumber("(555)555-5555")); // false
console.log(isEEUUPhoneNumber("2(757)6227382")); //false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment