Javascript Input Mask Phone Number Example


Share:
Published By: Admin, Published On: Jun 21, 2021, Category: Javascript
Hello Friends, Now let's see example of how to use javascript input mask phone number example. We will use how to use if input mask phone number in javascript. Here you will learn how to use javascript input mask phone number. This is a short guide on input mask phone number. Let's get started with how to input mask phone number in javascript. Here i will give you many example how you can check input mask phone number. Example : 1
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>javascript input mask phone number</title>
	</head>
	<body>
		<p>Masked on this blur event (remove focus):</p>
		<input type="text" id="test" placeholder="(999) 999-9999"/>
		<script type="text/javascript">
			document.getElementById('test').addEventListener('input', function (y) {
		  		var a = y.target.value.replace(/\D/g, '').match(/(\d{0,3})(\d{0,3})(\d{0,4})/);
		  		y.target.value = !a[2] ? a[1] : '(' + a[1] + ') ' + a[2] + (a[3] ? '-' + a[3] : '');
			});
		</script>
	</body>
</html>
Output :
Masked on this blur event (remove focus)
(654) 652-5452

It will help you....

Share: