Share via


Supporting ASP.NET MVC 3 Validation with Non-English Locales

This topic describes how to make sure that jQuery validation used in ASP.NET MVC 3 applications works with non-English locales.

Using ASP.NET MVC 3 Validation with Non-English Locales

To support validation for non-English locales in ASP.NET MVC 3 applications, you must include a locale-specific jQuery methods script file for each language you support. You can download these scripts from the following URL:

http://plugins.jquery.com/node/8/release

For example, for German locales, use the following file from the URL listed previously:

jquery.validate_17\jquery-validate\localization\methods_de.js

You then include the appropriate script reference in your view files, as in the following example:

<script src="@Url.Content("~/Scripts/methods_de.js")" type="text/javascript"></script>

You do not have to include the localized messages script (for example, messages_de.js for German locales), because ASP.NET MVC and types in the System.ComponentModel.DataAnnotations namespace use their own localized messages.

If you use a non-English locale, you should also use the correct locale-specific character for the decimal delimiter in the currency fields. (For example, in German, you would enter a price as "9,99".) On some non-English keyboards, the dot character (.) does not produce the English dot character used for decimal places. In those cases, if you use a dot character for the decimal point, you might see the following error:

The field Price must be a number.

In addition to including the localized methods script, you must make sure that the current locale on the server is set to the target locale so that any server-side messages (used for both client-side and server-side validation) will be used correctly. Typically when a server is configured, the correct locale is selected as part of the operating system installation. If the server is not set to the correct locale, do the following:

  1. In the Windows Control Panel, open Regional and Language Options.

  2. Select the Location tab

  3. In the Current location list, select the target locale

See Also

Tasks

How to: Implement Remote Validation in ASP.NET MVC

Other Resources

ASP.NET Globalization and Localization

Localizing ASP.NET Web Pages By Using Resources

ASP.NET MVC 3 Internationalization