Phone Mask

Size
1,850 Kb
Views
22,264

How do I make an phone mask?

What is a phone mask? How do you make a phone mask? This script and codes were developed by Kyle Michael Sullivan on 21 September 2022, Wednesday.

Phone Mask Previews

Phone Mask - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Phone Mask</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <label for="phone">Phone</label>
<input type="text" id="phone" onKeyUp="phoneMask(event)">
<button type="button" onClick="document.getElementById('phone').value=null">X</button> <script src="js/index.js"></script>
</body>
</html>

Phone Mask - Script Codes CSS Codes

label { font-weight:bold
}

Phone Mask - Script Codes JS Codes

function phoneMask(event) { var e = event.which; var P = document.getElementById("phone").value.replace(/\D+/g, ''); var L = P.length; if (e == 8) { // 8:backspace if (L < 11) { document.getElementById("phone").value = "(" + P.substring(0,3) + ") " + P.substring(3,6) + "-" + P.substring(6,10); } if (L < 7) { document.getElementById("phone").value = "(" + P.substring(0,3) + ") " + P.substring(3,6); } if (L < 4) { document.getElementById("phone").value = "(" + P.substring(0,3); } if (L < 1) { document.getElementById("phone").value = ""; } } else { if (L < 1) { document.getElementById("phone").value = null; } else if (L < 3) { document.getElementById("phone").value = "(" + P; } else if (L == 3) { document.getElementById("phone").value = "(" + P + ") "; } else if (L < 6) { document.getElementById("phone").value = "(" + P.substring(0,3) + ") " + P.substring(3,6); } else if ( L == 6) { document.getElementById("phone").value = "(" + P.substring(0,3) + ") " + P.substring(3,6) + "-"; } else if ( L < 11) { document.getElementById("phone").value = "(" + P.substring(0,3) + ") " + P.substring(3,6) + "-" + P.substring(6,10); } else { document.getElementById("phone").value = "(" + P.substring(0,3) + ") " + P.substring(3,6) + "-" + P.substring(6,10) + " x" + P.substring(10,13); } }
}
Phone Mask - Script Codes
Phone Mask - Script Codes
Home Page Home
Developer Kyle Michael Sullivan
Username GPMCTO
Uploaded September 21, 2022
Rating 3
Size 1,850 Kb
Views 22,264
Do you need developer help for Phone Mask?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Kyle Michael Sullivan (GPMCTO) Script Codes
Create amazing SEO content with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!