JQuery Validation Internationalization Problem

前端 未结 3 2144
悲&欢浪女
悲&欢浪女 2020-12-28 18:50

How can I change JQuery Validation plugin that gives error message at browser\'s language. I mean if I run it on a browser that has English language errors will be in Englis

3条回答
  •  长发绾君心
    2020-12-28 19:28

    Here's a suggestion for a simple way to set your custom validation message:

    1. Create a js file with XX_Messages.ee.js name with syntax:

     LANG = {
    
        PERSONAL_BIRTHDAY_CAN_T_BLANK : 'Birthday cannot be left blank',
        PERSONAL_COUNTRY_CAN_T_BLANK : 'Country cannot be left blank',
        PERSONAL_CITY_CAN_T_BLANK : 'City cannot be left blank',
    .......
    TEAM_EMAIL_NOT_VALID : 'E-mail is not a valid email address'
    };
    

    2.

    
    ....
    
        
            
        
    ....
    
    

    Note: import your XX_Messages.ee.js in html head where you want validation

    3.

    messages: {
                gender: {
                    required: LANG.PERSONAL_BIRTHDAY_CAN_T_BLANK
                },
                firstName: {
                    required:  LANG.PERSONAL_CITY_CAN_T_BLANK
                },
                lastName: {
                    required: LANG.PERSONAL_COUNTRY_CAN_T_BLANK
                }
            }
    

    Note: XX_Messages.ee.js file must be import in head of your html before your validation js.

提交回复
热议问题