Forced Field Validation

Sorry, I need some clarification…so you can’t find the page you have been working on in your Unbounce account?

Correct. When signing in I see the active page that I have directed traffic to and the SSD Copy I initially created off the original. However, the new variant I created with the URL: http://www.disabilitybenefitnetwork.com/ssd-test-page/ to specifically test outside of any traffic, I cannot seem to find in the unbounce interface. Thoughts?

Well I really doubt that it’s gone, unless you consciously selected to delete the page or “discard” the variant and then click again to “delete” the variant.

Let’s start with clarifying the difference between a page and a variant in Unbounce. A single page can have multiple variants in which all the variants point to the same URL, based on the weight you assign them.

Surly, your “SSD Copy” page has the variant that you have been working on within it.

These are pages

Capture

These (highlighted) are variants

Capture2

It was a filtering issue. Found the page.

I did make the updates on the SSD Test Copy page and tested it and all is working correctly. I copied the code over to the page I’m running traffic to and it’s not working there. I saved and republished and cleared my cache and I’m not seeing the errors on either the DOB or the Zip Code field. I went back and resaved a second time and I’m still not having any luck. Is there any further updates I need to make? Thoughts?

If you provide the URL to the page you run traffic to, I can look and see what may be going wrong.

Alternatively as a work-around, you could move your “SSD TEST Copy” variant and add it to the page you run traffic to, then point everything to that variant :wink:

Thanks! The variant I am pointing traffic to is http://www.disabilitybenefitnetwork.com/application/

I’d prefer to update the javascript on that page, so let me know if you can figure out what the issue is. Let me know if you need any further info. Thanks again!

@blynch1712

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>

Thanks so much Kyle! I do not what I am doing wrong. It is not working. This is what is showing in the webpage after I add the script.

Ah I see what you need. That requires a more detailed line of regex. Replace that var valid with the following and it will work for number between 20 and 500.

var valid = /(?<!-)\b([2-9][0-9]|1[0-9][0-9]|2[0-9][0-9]|3[0-9][0-9]|4[0-9][0-9]|500)\b/.test(value);

I’m a bit of a rookie with regex logic so let me know if that works on your page!

1 Like

Thanks Kyele! Somebody from the group pass me a script. It is working great. The script is:

<script>
  
  lp.jQuery(function($) {
  
    var ruleID = 'custom';
    var field = 'number';
    var message = 'Please enter a valid number';
  
    var rules = module.lp.form.data.validationRules[field];
  
    $.validator.addMethod(ruleID, function(value, field) {
  
      var valid = ( /^([2-8][0-9]|9[0-9]|[1-4][0-9]{2}|500)$/.test(value) );
  
      return valid || (!rules.required && !value);
    }, message);
  
    rules[ruleID] = true;
  
  });
</script>
1 Like

Perfect! Glad you got it working :slight_smile:

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?

Hey @erikleist

A simple fix is to edit the regex. The example below validates from 21-200

var valid = ( /^([2-8][1-9]|9[0-9]|[1-2][0-9]{2}|200)$/.test(value) );

Hope that helps :slight_smile:

1 Like

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 okay, I understand. You want to use it with the birth year and not the number of years. Sorry I should’ve gotten that the first time :wink:

The line below should will work. But keep in mind that it will have to be changed every year to include the new digit allowing 21 or older.

var valid=(/^([0-9]{2})\/([0-9]{2})\/(194[0-9]|195[0-9]|196[0-9]|197[0-9]|198[0-9]|199[0-8])$/.test(value));
1 Like

Oh very cool! Worked and created a calendar reminder for Jan 1 :slight_smile:

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.