5 examples of 'regex for 10 digit us phone number' in JavaScript

Every line of 'regex for 10 digit us phone number' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
42public getDigits(phone: string): string {
43 const numbers = phone.match(/\d+/g)
44 if (numbers === null) return ''
45 return numbers.join('')
46}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

1function formatPhoneNumber(phoneNumberString: string) {
2 var cleaned = ("" + phoneNumberString).replace(/\D/g, "");
3 var match = cleaned.match(/^(1|)?(\d{3})(\d{3})(\d{4})$/);
4
5 if (match) {
6 var intlCode = match[1] ? "+1 " : "";
7 return [intlCode, "(", match[2], ") ", match[3], "-", match[4]].join("");
8 }
9
10 return phoneNumberString;
11}
40function isValidPhone(value) {
41 return /^[0-9]+$/ig.test(value)
42}
790function isPhoneNumber(number) {
791 var regex = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;
792 return regex.test(number);
793}
269static phone(value) {
270 var reg = /^((\d{10,11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)$/;
271 return reg.test(value);
272}

Related snippets