Skip to main content

Hi


I need to validate the length and only digits in a zip code field.


As far as I can see it’s only possible to validate email and phone as default in Unbounce?


<script type="text/javascript"\>  
var d = window.module.lp.form.data;
/\* Change the main error message title \*/
jQuery(document).ready(function() {
jQuery('#'+d.errorContainerId).find('h3').text(
"Please correct the following errors:"
);
});
/\* Change the individual error messages \*/
d.validationMessages = {
"customer_full_name": {
required: "Type your name"
},
"customer_full_address": {
required: "Type your address"
},
"customer_email": {
required: "Type your email",
email: "Please type a valid email"
},
"customer_zipcode": {
required: "Type your zip code",
},
"customer_phone": {
required: "Type your phone number",
phone: "Type a valid phone number"
},
};
</script>

Found a solution:


<script>
lp.jQuery(function($) {
var ruleID = 'zipcode';
var field = 'customer_zipcode';
var message = 'Indtast kun postnummeret';
var rules = module.lp.form.data.validationRules[field];
$.validator.addMethod(ruleID, function(value, field) {
var valid = /^(?:[0-9]{4})?$/.test(value);
return valid || (!rules.required && !value);
}, message);
rules[ruleID] = true;
});
</script>

Can you send me a this type of page file?

So that i can Understand clearly. It will be helpfull


Reply