Question:
Is it possible to automatically add a dash \"-\" in auto complete?
Let say I have a phone number field and if someone will type their phone number
You can try this code.
$(function () {
$('#txtnumber').keydown(function (e) {
var key = e.charCode || e.keyCode || 0;
$text = $(this);
if (key !== 8 && key !== 9) {
if ($text.val().length === 3) {
$text.val($text.val() + '-');
}
if ($text.val().length === 7) {
$text.val($text.val() + '-');
}
}
return (key == 8 || key == 9 || key == 46 || (key >= 48 && key <= 57) || (key >= 96 && key <= 105));
})
});
HTML input
You can also see in jsfiddle
https://jsfiddle.net/karthikjsf/38vdpj4f/