I want to add zip validation on my checkout page like right now if somebody put zip code like *6722 the order place I want some validation for special characters.
-
what is format support?Amit Bera– Amit Bera ♦2019年09月11日 07:58:39 +00:00Commented Sep 11, 2019 at 7:58
-
how i check where i can check this?@Amit Beraimtiazau– imtiazau2019年09月11日 08:00:19 +00:00Commented Sep 11, 2019 at 8:00
1 Answer 1
There two files you need to create.
First,Add additional CSS class to Postcode using plugin https://magento.stackexchange.com/a/205672/4564
namespace MODULE\NAME\Model\Plugin; class AttributeMergerPlugin { public function afterMerge(\Magento\Checkout\Block\Checkout\AttributeMerger $subject, $result) { if (array_key_exists('postcode', $result)) { $result['postcode']['additionalClasses'] = 'your_css_custom_class'; } return $result; } }Second, create a custom validation rule for javascript: Link: https://magento.stackexchange.com/a/192407/4564
file code: Vendor_Module/view/frontend/web/js/validation-mixin.js
define([
'jquery'
], function ($) {
"use strict";
return function () {
$.validator.addMethod(
'your_css_custom_class',
function (value) {
// Some custom validation stuff here
return true or false;
},
$.mage.__('Your validation error message')
);
}
});