(jquery) masked input plugin overwrites text when maxlength is reached

Viewed 11286

Let's say I have a input like this:

$('#phone').mask("?99999", { placeholder: "" });

If I type '12345', then put the cursor between 3 and 4, and press 1, the text will be like: '12314'

I'd like a behavior like maxlength, that prevents any additional character when the limit is reached, so the text would stay '12345' if maxlength = 5.

This is the plugin: http://digitalbush.com/projects/masked-input-plugin/

5 Answers

Adding it as an attribute with jQuery worked for me:

$('#phone').mask("?99999", { placeholder: "" }).attr('maxlength', 5);

Related