jQuery:maskedinput插件不能与验证插件配合使用 [英] jquery: maskedinput plugin not playing nice with validation plugin

查看:79
本文介绍了jQuery:maskedinput插件不能与验证插件配合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚从jquery开始,正尝试使用 validation进行表单验证插件.然后,我发现了maskedinput插件( http://digitalbush.com/projects/masked-input-插件/),并尝试在电话号码字段中使用它.

Just started with jquery and am trying to get form validation to work using the validation plugin. Then I discovered the maskedinput plugin (http://digitalbush.com/projects/masked-input-plugin/) and tried to use it on a phone number field.

工作到一定程度: 当电话字段成为焦点时,它将显示占位符,并允许您输入电话号码并限制为数字-非常好!

Things work to a point: When the phone field comes in focus it displays the place holders and allows you to enter a phone number and limits you to digits - very nice!

但是,如果您仅输入9位数字而不是必填的10位数字(假设美国电话号码),是的,可能性不大,但是更疯狂的事情已经发生,并且会发生,然后单击提交",那么电话字段中已经存在的任何内容都会已清除.如果您输入完整的电话号码,但在其他某些字段上验证失败,则电话字段中的输入将保留.

However, if you only enter 9 digits instead of the required 10 (assuming US phone number), yes, unlikely, but crazier stuff has and will happen, and you click submit, then anything that was already in the phone field is cleared. If you enter the entire phone number and validation fails on some other field the entry in the phone field sticks.

如何防止这种情况?

谢谢 hgg

推荐答案

如果您使用屏蔽输入插件
,则它以这种方式工作,它允许所有值或全部不输入
,因此如果您使用屏蔽输入,最好不要使用屏蔽输入如果需要9/10个值,则bcoz屏蔽的输入可以具有有限数量的值,
不少于此

if you use the masked input plugin
it works in that way it allow all the values or none
so better not use masked input if you want 9 / 10 values , bcoz masked input can have limited number of values as much defined
not less not more than that

这篇关于jQuery:maskedinput插件不能与验证插件配合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆