9

I am using jQuery masked input plugin. However when I set the mask, any existing value in the input field is being destroyed. Doing the following:

$(".priceSKUID").mask("**-***-******", { placeholder: " " });

There must be a way to deal with existing values which are programmatically placed into the input field.

Yi Jiang
  • 49,435
  • 16
  • 136
  • 136
plippard
  • 375
  • 2
  • 3
  • 17
  • 1
    Masked Input is a little limited and bugged. Can you try [meioMask](http://www.meiocodigo.com/projects/meiomask/)? Is very similar. – David Rodrigues May 27 '11 at 02:09

3 Answers3

3

When you set a mask like 9999, the value of the input has to be 9999. But, if we have a mask with some optional characters like 9?999, it means that if the value have just one character, it will be displayed. In other words, the last three characters are opitional. I just tried it and works fine.

Leandro
  • 31
  • 2
3

$('#my').mask('99.99').val('25.00') is not working

It should have trigger('input')

$('#my').mask('99.99').val('25.00').trigger('input')
Yogesh
  • 655
  • 5
  • 13
2

You can set it vía javascript after calling

<input id='my' />

...

$('#my').mask('99.99').val('25.00')

You must honor the mask format by setting the value this way. Its not that simple but is the only way i found to achieve this goal.

animuson
  • 53,861
  • 28
  • 137
  • 147
jpaoletti
  • 855
  • 1
  • 13
  • 21