Search code examples
jquerymaskmaskedinput

How to pre-populate 9 with jQuery Masked Input Plugin?


I am using Masked Input Plugin from digitalBush for jQuery, which is very simple to use.

For some cases, I want to pre-populate data for the client, so for something like this :

.mask("123999")

client will see:

123___

And will need to insert last 3 digits. It's working fine till the moment I want to pre-populate number 9, to show something like this:

129___

When I am making mask as "129999", user see 12____

Is it even possible to have mask with this plugin that is visible for the user as 129___?


Solution

  • You can redefine masked input definitions like this:

    $.mask.definitions['9'] = '';
    $.mask.definitions['d'] = '[0-9]';
    

    And then use this mask:

    .mask("129ddd")