使用jQuery验证货币字段的客户端验证 [英] client validation using jQuery validate for currency fields

查看:117
本文介绍了使用jQuery验证货币字段的客户端验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在asp.net mvc 3应用程序上使用jquery.validate时遇到问题.

I have a problem using jquery.validate on my asp.net mvc 3 app.

至少在西班牙,我们使用,"将数字与小数点分开.好吧,如果我输入类似的内容,请使用服务器端验证:

At least in Spain we use the "," to split a number from its decimals. Ok, using server side validation, if I put something like:

12.55,当服务器验证它时,表明该值无效.如果我输入:12,55可以.

12.55 when the server validate it, it says that the value is not valid. If I put: 12,55 it works.

到目前为止很好,但是如果我使用jQuery validate,它说12,55是无效的,而12.55是有效的.因此,客户端通过验证但服务器未通过验证,或者客户端未通过但服务器通过了验证.

So far so good, but if I use jQuery validate, it says that 12,55 is invalid and 12.55 is the valid one. So, the client pass the validation but the server not, or the client doesnt pass but the server would.

那么...我可以更改这种验证的语言环境吗?

So... can I change the locale for that kind of validation?

谢谢.

PS :服务器如何知道我要使用,"而不是."进行验证?我不记得我是否在某处指定了那个.

PS: How the server knows that I want to validate using "," and not "."? I don't remember if I specified that somewhere.

推荐答案

可能您应该包括本地化文件:

Probably you should include localization files:

http://ajax.aspnetcdn.com/ajax/jQuery.Validate/1.7/localization/messages_es.js

http://ajax.aspnetcdn.com/ajax/jQuery.Validate/1.7/localization/methods_de.js

在德国,数字使用相同的规则,因此您可以使用methods_de.js或只包含

In Germany one uses the same rules for numbers, so you can use methods_de.js or just include

jQuery.extend(jQuery.validator.methods, {
    number: function(value, element) {
        return this.optional(element) ||
               /^-?(?:\d+|\d{1,3}(?:\.\d{3})+)(?:,\d+)?$/.test(value);
    }
});

此处由Microsoft CDN托管的1.6版文件列表. 1.7版具有相同的文件.

Here the list of files hosted by Microsoft CDN for the version of 1.6. The version 1.7 has the same files.

已更新:请参见演示此处

这篇关于使用jQuery验证货币字段的客户端验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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