jquery masked input plugin to not clear field when errored

McKay picture McKay · Mar 20, 2012 · Viewed 46.5k times · Source

I'm looking at the http://digitalbush.com/projects/masked-input-plugin/

I'm calling it like this:

$(control).mask('999-999-9999');

And I don't want it to throw away the users input if something is wrong, e.g. they haven't finished

[407-555-____]

If you leave the field after having typed this much, it clears it. I'd like to leave it so they can finish later.

I'm new to jQuery, and I've looked through his source, but I can't find any way to do that, nor can I find any way to edit it to accomplish what I want, because the code is arcane to my eyes.

Answer

Angela Nicholas picture Angela Nicholas · Feb 7, 2014

Set autoclear option to false.

$(control).mask('999-999-9999', {autoclear: false});