mobile number format (xxx) xxx-xxxx
// For this type format xxx-xx-xxxx
$(document).on('keyup','your input element',function(){
let text=$(this).val()
text=text.replace(/\D/g,'')
if(text.length > 3) text=text.replace(/.{3}/,'$&-')
if(text.length > 6) text=text.replace(/.{6}/,'$&-')
$(this).val(text.substring(0,11));
});
//For this type format (999) 999-9999
$(document).on('keyup','Your input element',function(e){
let text=$(this).val()
text=text.replace(/\D/g,'')
text=text.replace(/.{0}/,'$& ( ' )
text=text.replace(/.{6}/,'$& ) '); //Add hyphen at pos.4
text=text.replace(/.{12}/,'$&-') //Add hyphen at pos.8
$(this).val(text.substring(0,17)); //Set the new text
});
Also in JavaScript:
- react history listen get previous location
- command reboot android app react native adb command
- how to get element by attribute value in javascript
- js multiple try catch
- Unterminated quote at columns 0-8 ['MM-yyyy] in expression ['MM-yyyy]
- reusable table in react js
- less than equal to in javascript
- create callback function javascript
- js get first letter of string
- Robux gift
- js entries
- how to change style of an element using javascript
- moment check valid date
- devexpress dxdatagrid custom text field link
- split the numbers js
- CChartpie react
- p5 js lines
- jspdf reduce size file
- dummy api json
- includes()
- simple javascript code
- nsenter
- anime.js morph svg d value
- js code