Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript phone number mask

// JAVASCRIPT
document.getElementById('phone').addEventListener('input', function (e) {
  var x = e.target.value.replace(/D/g, '').match(/(d{0,3})(d{0,3})(d{0,4})/);
  e.target.value = !x[2] ? x[1] : '(' + x[1] + ') ' + x[2] + (x[3] ? '-' + x[3] : '');
});

// HTML
<input type="text" id="phone" placeholder="(555) 555-5555"/>
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #phone #number #mask
ADD COMMENT
Topic
Name
1+3 =