开发者

Input mask with JQuery and regexp

开发者 https://www.devze.com 2023-04-10 16:55 出处:网络
I\'m looking for a Javascript or JQuery solution (client side) to : Mask input: prohibit the user to enter an illegal character

I'm looking for a Javascript or JQuery solution (client side) to :

  • Mask input: prohibit the user to enter an illegal character
    • Accept regexp like ^[-+]?[0-9]+(\.[0-9]+)?
  • Format the input
    • thousands separator= ,
    • decimal separator= .

For example, I want 1234.56 to be display (change to) '1,234.56`.

Masked Input Plugin can't allow the formatting (I can't tell it [0-9]+ before the decimal separator).

meioMask allows 999.999.999.999,99 format, but the value is converted to string. The binding with Dou开发者_JS百科ble in Java fails.

Do you have proposals, areas of research?


I followed the advice of Ayman Safadi and I've used plugins.jquery.com/project/numberformatter to format and parse the input.

I store the value entered in the alt field and restore to the value when the user focus (and format onBlur).

This solution does not block the entry (eg prevent type a letter in an amount). Any other ideas should be appreciate.

0

精彩评论

暂无评论...
验证码 换一张
取 消