After few hours of experimenting I made some changes for previous code which works for my problem:
jQuery(document).ready(function () {
Validation.add('validate-postcode', Translator.translate('Please enter a valid post code.'), function (v, elm) {
var elem1 = jQuery(elm),
relatedElem = jQuery('#' + elem1.attr('data-related-field')),
passed;
elem1.removeClass('validation-failed');
elem1.removeClass('validation-passed');
if (typeof relatedElem !== 'undefined') {
relatedElem.removeClass('validation-failed');
relatedElem.removeClass('validation-passed');
passed = !Validation.get('IsEmpty').test(elem1.val()) &&
!Validation.get('IsEmpty').test(relatedElem.val()) &&
/^\d{3}$/.test(elem1.val()) &&
/^\d{2}$/.test(relatedElem.val());
if (!passed) {
relatedElem.addClass('validation-failed');
elem1.addClass('validation-failed');
}
}
return passed;
});
});
Hope that help or inspire someone for better solution.
"Document ready" was required due Translator.translate() existence.
Translation of string "Please enter a valid post code." was added in jstranslator.xml file.
Note :- make sure in form tag do not use data-mage-init='{"validation":{}}' else it will init default js you need to init the validation and then use errorPlacement call back write you logic
Best Answer
modified the below files replace full code in dob.phtml
in edit.phtml add below script in the end of the file
make sure dob attribute enable from admin :-)