client validation using jQuery validate for currency fields

后端 未结 2 1275
不思量自难忘°
不思量自难忘° 2020-12-22 03:59

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 validat

相关标签:
2条回答
  • 2020-12-22 04:12

    You could try configuring your web application to use the locale of the client web browser:

    <system.web>
        <globalization requestEncoding="utf-8" 
                       responseEncoding="utf-8"
                       culture="auto" 
                       uiCulture="auto" />
        ...
    </system.web>
    

    This will use the browser culture for server side validation. As far as the client side validation is concerned it already uses the browser culture. So this ensures that both match.

    0 讨论(0)
  • 2020-12-22 04:22

    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

    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);
        }
    });
    

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

    UPDATED: See demo here.

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