Javascript Input Mask Phone Number Example
Jun 21, 2021 . Admin

<!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....