5 examples of 'phone number masking javascript' in JavaScript

Every line of 'phone number masking javascript' 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
16function js_phone( phone )
17{
18 if ( parseInt( phone ) == 0 )
19 return '';
20 var len = phone.length;
21 var result = phone;
22 if ( len > 10 )
23 result = result.insert( -10, ' (' ).insert( -7, ') ');
24 if ( len > 4 )
25 result = result.insert( -4, '-' ).insert( -2 , '-' );
26 return ( len > 10 ? '+' : '' ) + result;
27}
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

42public getDigits(phone: string): string {
43 const numbers = phone.match(/\d+/g)
44 if (numbers === null) return ''
45 return numbers.join('')
46}
21export function isValidLength(phone: string): boolean {
22 return phone.length >= PHONE_MIN_LENGTH && phone.length <= PHONE_MAX_LENGTH;
23}
40function isValidPhone(value) {
41 return /^[0-9]+$/ig.test(value)
42}
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}

Related snippets