I am trying to apply masked input plugin ( jquery.maskedinput.min.js ) to a password field in order to create :
****-****-****
It is basically a registration key separated by dashes.
$(document).ready(function(){
$("#registrationKey").mask("9999-9999-9999");
$("#registrationKey").keyup(function(e) {
self = $(this);
rkValue = self.val().replace(/[^\d\-]/g, '');
self.val(rkValue);
console.log("value = " + rkValue);
self.attr("regKey", rkValue);
});
});
<input type="password" id="registrationKey" name="registrationKey" regKey="" maxlength="15" autocomplete="off" >
I am having 2 problems. First one is that the field is already populated due to mask being applied. Second problem is it won't apply a dash after every 4th digit.
Is there a way to accomplish this via pure javascript or via this plug-in?
By the way, I have seen something similar in another post. However, it is very buggy if a user places the mouse in the middle of the field, or highlights some section of the text and deletes it.
Any ideas?
thanks