I’m looking to find a way to force field validation on 3 different fields on my page:
Phone Field: XXXXXXXXXX (must be 10 numeric values only)
Zip Code: XXXXX (must be 5 numeric values only)
DOB: must be MM/DD/YYYY format only
Help!!
I’m looking to find a way to force field validation on 3 different fields on my page:
Phone Field: XXXXXXXXXX (must be 10 numeric values only)
Zip Code: XXXXX (must be 5 numeric values only)
DOB: must be MM/DD/YYYY format only
Help!!
Your Date of Birth field name and ID is “dob” and it needs to be “date_of_birth”
Hi!
The work email is working just fine!
But is there a way to valid a text form an array?
Example: Show error message when the text is not “text 1” or “text 2” or “text 3”
Thanks!
Hi Kyle! How can I validate to allow just 3 digit number?
I’ve made some edits to the var valid…The script below should work. You can change the field name and message as needed in your case.
< script>
lp.jQuery(function() {
var ruleID = 'dob' var field = 'date_of_birth';
var message = 'Please enter a date in this format: 123';
var rules = module.lp.form.data.validationRules[field];
.validator.addMethod(ruleID, function(value, field) {
var valid = /^([0-9]{3})$/.test(value);
return valid || (!rules.required && !value);
}, message);
rules[ruleID] = true;
});
</script>
This is great and I just used it. Can you think of a quick way in this format to also verify the age of the individual is at least 21?
I updated the regex and the error message now display on any age or date format: https://www.screencast.com/t/bMvjDlriqg5
<script>
lp.jQuery(function($) {
var ruleID = 'birthday';
var field = 'birthday';
var message = 'Please enter a date in this format: MM/DD/YYYY';
var rules = module.lp.form.data.validationRules[field];
$.validator.addMethod(ruleID, function(value, field) {
var valid = ( /^([2-8][1-9]|9[0-9]|[1-2][0-9]{2}|200)$/.test(value) );
return valid || (!rules.required && !value);
}, message);
rules[ruleID] = true;
});
</script>
Oh very cool! Worked and created a calendar reminder for Jan 1 🙂
Do you know if there’s any way to make this scrip AMP compliant?
AMP will be releasing script functions conditionally soon. Right now, there is no way to use custom scripts for AMP.
Hi Kyle, if I understand it correctly, this script only makes sure the date is in 12/12/1222 format - it only checks the quantity of numbers (only possible to use 0-9) between the slash symbols. For my client I need to force validation of the date in UK format - dd/mm/yyyy. So that it is not possible to type in date such as 09/31/2022 (US date format) since there are only 12 months in a year.
So it should force this change 31/09/2022
Can you help me with that please?
PS: My field ID and therefore var field in the code is ‘date_of_your_event’, do I need to change the ruleID somehow as well?
I followed the exact same steps and it is not throwing any errors when I fill the DOB field incorrect.
Does anyone know of the script still works?
Thanks
Hey @Ronald_Tu I’m happy to help. Could you share the URL to the page?
Thanks Kyle!
The idea is to force the input date value to match the required mailchimp date format. This way I could setup the api connection between Unbounce and Mailchimp.
Okay I think it’s a simple fix!
It’s an older script so you need to make sure the following 2 scripts are in the page:
jQuery (1.4.2)
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
jQuery.Fancybox (1.3.4)
<link href="//assets.unbounce.com/m/lp-webapp/jquery.fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.css" media="screen" rel="stylesheet" type="text/css">
<script src="//assets.unbounce.com/m/lp-webapp/jquery.fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.js"></script>
Make sure the placement for the validator function is “Before Body End Tag” not in the “Head.”
@Ronald_Tu, A quick check… in your Chrome do you see the error “lp is not defined?”
@xavier.bussonnais - Where would find that error? I don’t see anything like that on my browser window. Could you screenshot where the error “Ip is not defined” would show up?
Thanks,
Ron
The page URL is shared at the top of the thread. It looks like he ran into the same problem you had.
@xavier.bussonnais could you share the script you edited to get it working?
Hey @xavier.bussonnais, this seem to have worked. But Now I am running into another error, when I put in the proper date format in, it is firing off the error message.
Hi! I am trying to use this script to validate date of birth in my form as (MM/DD/YYYY) and can’t get it to work. The validation error won’t show up when I’ve tested it out using the incorrect formatting.
Below are screenshots of the scripts I’ve placed on the landing page, as well as my form setup.
Hi @lasuma12,
This is probably because the jQuery script is being loaded after your validation script.
Best,
Hristian
Hi! Thank you for your response! I moved the jQuery script to the Head of the page and republished. When I tested, the verification for age still didn’t show an error when I typed it it incorrectly.
Should the Form Field type be a Single-Line Text or something else? I’ve followed all of the steps above as far as I can tell. Not sure why this isn’t working. Is there any other solution for this?
No account yet? Create an account
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.