I have a customer address attribute "postcode" and I have AttributeMergerPlugin.php file in that i added validation class for the postcode
if (array_key_exists('postcode', $result)) {
$result['postcode']['additionalClasses'] = 'required postcode_custom_class checkout-no-display';
$result['postcode']['validation']['postcodevalidation'] = true;
$result['postcode']['validation']['postcodeformatvalidation'] = true;
$result['postcode']['validation']['required-entry'] = false;
}
and i added the validation rule in validator-mixin.js
validator.addRule(
'postcodeformatvalidation',
function(value) {
var regexp = /^[A-Z]{1,2}[0-9RCHNQ][0-9A-Z]?\s?[0-9][ABD-HJLNP-UW-Z]{2}$|^[A-Z]{2}-?[0-9]{4}$/;
var zipcode = value.toUpperCase();
return regexp.test(zipcode);
},
$.mage.__("Enter the full postcode to proceed further.")
);
Currently its validating the postcode format. But what happening is once user enter the correct postcode the message is not disappering until unless user clicked on next button, it creating the confusion for user weather they entered postcode is correct or not. So i need to do a validation on user input so if the input is match the format error message automatically disapper.
How can i achieve this? Thanks