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

            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

1 Answer 1


Currently the condition returns value for both valid and invalid results. So instead return regexp.test(zipcode); try with return (regexp.test(zipcode)==false); So you will get message only for invalid inputs.

But, not sure about the regexp which you are using to validate postcode. I am using the following

var regexp = /^[0-9]{10}|[0-9]{6}$/;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.