Magento – Customize the validation error messages of validation.js in magento


In my magento application the checkout page , will displays error message using validation.js file.

when i click to continue in the new billing address without entereing some value it displays error message as This is required field..

I want to change this message as its corresponding field name .

enter image description here

Instead of that error message i need to display as First name is a required field..

How can i do this ?


this is the input box which is located in customer/widget/name.phtml as:

<input type="text" id="<?php echo $this->getFieldId('firstname')?>" name="<?php echo $this->getFieldName('firstname')?>" value="<?php echo $this->escapeHtml($this->getObject()->getFirstname()) ?>" title="<?php echo $this->getStoreLabel('firstname') ?>" maxlength="255" class="input-text validate-firstname" <?php echo $this->getFieldParams() ?> />

enter image description here

This is the output.

Best Solution

You can create another class in your validation.js file something like validate-firstname and add something like this in your validation.js file

 ['validate-firstname', 'First name is required field.', function(v) {
            return !Validation.get('IsEmpty').test(v);

Search for this validate-alpha validation line and after put this code in your js file and add validate-firstname class in your firstname input field.