I am trying to make an account number like this "12-1234-12-12-12345-123" using keyup event in jquery
I tried this stackoverflow link . it works for every two characters. But my case is a little bit different. My case is not every 2 characters. I have to make a dash("-") like this 12-1234-12-12-12345-123
I tried this below code
$('#ContentPlaceHolder1_txtAccount1').keyup(function () {
console.log("key press working");
var foo = $(this).val().split("-").join(""); // remove hyphens
var accSplit = $(this).val().split("-");
if (accSplit.length == 0) {
if (foo.length > 0) {
foo = foo.match(new RegExp('.{1,2}', 'g')).join("-");
}
}
if (accSplit.length == 1) {
if (foo.length > 0) {
foo = foo.match(new RegExp('.{1,4}', 'g')).join("-");
}
}
$(this).val(foo);
});