Conflict between jQuery Validate and Masked Input

后端 未结 7 642
梦谈多话
梦谈多话 2020-12-08 10:40

I\'ve got a form that\'s using both jQuery Validate and Masked Input for phone number and US zip code fields.

For example, for a US zip code, Masked Input allows only

相关标签:
7条回答
  • 2020-12-08 11:09

    I had a similar problem and managed to solve it changing the default placeholder character to an empty string.

    I was using a .mask('9?99'); and was validating with a simple 'number' rule, and was having the same kind of conflict.

    I changed the mask declaration to .mask('9?99',{placeholder:''}); and... no more conflict. :)

    There's a possible problem in your case, because of the - in the zip code, which is always inserted in the form by the mask plugin. I think you can change the regexp to ^\d{5}\-$|^\d{5}\-\d{4}$ (matching the dash in both cases) and it should validate then.

    Anyway, you posted a while ago and probably don't need this anymore but perhaps it'll help someone else. :)

    0 讨论(0)
提交回复
热议问题