This gave a bit of a headache but I have found the solution for this.
The solution does not cover how to attach or disable warning messages to input fields but answers the question.
Context:
Every time you change the postal code an ajax call is made and the shipping rates are recalculated.
The execution will eventually enable the script located at:
vendor/magento/module-checkout/view/frontend/web/js/model/shipping-rates-validator.js
which in turn will call
vendor/magento/module-checkout/view/frontend/web/js/model/postcode-validator.js
Now depending on the result that the latter returns the shipping-rates-validator will display or not display the warning message.
as seen here:
postcodeValidation: function () {
var countryId = $('select[name="country_id"]').val(),
validationResult,
warnMessage;
if (postcodeElement == null || postcodeElement.value() == null) {
return true;
}
postcodeElement.warn(null);
validationResult = postcodeValidator.validate(postcodeElement.value(), countryId);
if (!validationResult) {
warnMessage = $t('Provided Zip/Postal Code seems to be invalid.');
if (postcodeValidator.validatedPostCodeExample.length) {
warnMessage += $t(' Example: ') + postcodeValidator.validatedPostCodeExample.join('; ') + '. ';
}
warnMessage += $t('If you believe it is the right one you can ignore this notice.');
postcodeElement.warn(warnMessage);
}
return validationResult;
},
It is only logical that if the postcodeValidator(postcode-validator.js) will always return true the warn message will never be displayed.
Therefor we override the postcode-validator.js
Step 1:
Create file at [Namespace]/[Module]/view/frontend/web/js/model/postcode-validator.js with he following content:
define(['mageUtils'], function (utils) {
'use strict';
return {
validatedPostCodeExample: [],
validate: function(postCode, countryId) {
return true;
}
}
});
Step 2:
Map any request made to the postcode-validator to our script.
Create file at [Namespace]/[Module]/view/frontend/web/requirejs-config.js with the following content:
var config = {
map: {
'*': {
'Magento_Checkout/js/model/postcode-validator':'Namespace_Module/js/model/postcode-validator'
}
}
};
Step 3:
php bin/magento cache:clean
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy
I don't know if this is the cleanest solution ever but does the trick. Hope this helps.