jquery.maskedinput programmatically set value and apply mask?

Viewed 14014

I'm using DigitalBush's MaskedInput jquery plugin. I have a simple input box for a phone number:

$('#txt_PhoneNumber').mask('(999) 999-9999');

Sometimes the field is programmatically filled with a non-formated number such as 5551234567. How can I notify the mask input to apply it's mask to "beautify" it's new input?

4 Answers

After set the value, call the jQuery trigger fn.

$('#txt_PhoneNumber').trigger('keyup');

Works for me.

jquery.mask.js @version: v1.14.16

Related