jQuery validate-在验证发生之前替换字段中的逗号 [英] jquery validate - replace commas in field before validation occurs

查看:99
本文介绍了jQuery validate-在验证发生之前替换字段中的逗号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看来,即使使用当前的validate插件,如果要使用min进行验证,也不能在值中包含逗号.我在github上找到了几个月前(11个月)提交补丁的文件,以修改源.js文件,但该文件仍未发布.

It appears that even with the current validate plugin you can't have a comma in a value if you want to validate using min. I found on github where the patch was submitted several months ago (11 months) to modify the source .js file but it's still not in release.

因此,我没有修改我的源.js文件,而是试图弄清楚在验证之前如何替换逗号.

So instead of modifying my source .js file I'm trying to figure out how to replace the comma prior to validation.

我尝试过这样的事情:

$("#amount").blur(function(){
    var val = $(this).val().replace(/\,/g,'');
    $(this).val( val ); 
});
$("#transferForm").validate({
    .......
});

但是它先运行验证,由于最小而失败,然后替换该值.我并不一定希望它无法通过验证并告诉用户删除逗号-我只希望它在运行min规则之前删除逗号.

But it runs validate first, fails because of min and then replaces the value. I don't necessarily want it to fail validation and tell the user to remove commas - I just want it to remove the comma before running the min rule.

推荐答案

甚至不让他们输入逗号

$("#amount").keyup(function(){
    var val = $(this).val().replace(/\,/g,'');
    $(this).val( val ); 
});

演示: http://jsfiddle.net/calder12/tdxKv/

这篇关于jQuery validate-在验证发生之前替换字段中的逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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