Magento 2 Modify/Update Existing Validation Message Text

In Magento 2, sometimes we have a requirement to customize or update existing message text given. So this is really simple in Magento 2 as we have to only do the following for that.

Let’s say there is a custom form where we have to apply this custom validation message text, so there we have to edit existing message by using following code snippet:

Standard Format:

$('#form-to-validate').mage('validation', {
    messages: {
        'input-name': {
            'validation-rule-1': 'Validation message 1',
            'validation-rule-2': 'Validation message 2',
        },
    }
});

Sample example:

$('#customformId').mage('validation', {
    messages: {
        'form_input_field_id': {
            'required': 'This is my custom required validation message', 
            // "required" is an in-built Magento validation rule
        },
    }
});

Hope this helps you guys!

Leave a Reply