[How to] Detect Matching First + Last Name Script (Stop Empty / Blank / Spacebar Leads)

Hello all!

I wanted to share a script I modified, that now prevents matching First + Last Name fields from being submitted. This script also works well if you’ve been receiving empty leads lately, as it turns out those leads aren’t in fact empty! After speaking with Bruna in Unbounce Support I was surprised to find out most fields marked as required (aside from email) can actually be bypassed by entering in a space, this results in what appears to be empty leads showing.

This script is meant to prevent submissions with matching first + last names, obviously we don’t see too many “Michael Michael” or “Susan Susan” names in the wild, yet we see spam of that nature! Since single spaces in each name field match, this will also prevent empty (spaced) lead submissions.

<script>
  
  lp.jQuery(function($) {
  
    var ruleID = 'FLnameMatch';
    
    //The first name field to check against
    var firstNameField = 'first_name';
    
    //The second name field
    var secondNamefield = 'last_name';
    
    var message = 'Input Error, Please Contact Us';
  
    var rules = module.lp.form.data.validationRules[secondNamefield];
  
    $.validator.addMethod(ruleID, function(value, secondNamefield) {
      
      var nameValue = $('#' + firstNameField ).val(); 
      var valid = ( value !== nameValue );
  
      return valid || (!rules.required && !value);
    }, message);
  
    rules[ruleID] = true;
  
  });

</script>

You can include this script on single landing pages by adding it to the Javascripts section when editing the page. If ALL of your forms on landing pages have First + Last Name you should also be able to add this globally instead of on every single landing page (avoiding the need for multiple page edits).

Credit where it’s due: I found the original script in this community, I meant to share the page URL with Bruna during our support chat but haven’t been able to locate my bookmark on it, so I can only take a little credit for the slight alteration and for realizing this works well on “spaced” first + last name empty lead submissions!

Hope this is helpful! If a moderator could please move this to Tips + Scripts category on here please, I think it would be very beneficial to others!

5 Likes

This is AMAZING @Michael_Miller!! I’ll move this into Tips and Scripts, thank you so much for sharing it here! This is tremendously helpful!

-Jess

1 Like

Thank you Michael, I appreciate this.

1 Like

This doesn’t seem to be working for me. Still lets through submissions with the same first name. Not sure what I’m doing wrong as the code snippet is pretty straight forward

Hi Trevor,
I have not yet tried this. I was contacted by Michael Miller about it - unbounce@discoursemail.com

The most common cause for these issues is if you’re running other javascript on your page, they can potentially cancel each other out. Additionally, multiple versions of jquery can cause scripts to break. Check on those, that may solve your problem :slight_smile:

-Jess

1 Like

Jess is right, sometimes it can be another Javascript running try changing the placement. If that doesn’t work, you could also try adding another script to define the jQuery version being used, for example, add another Javascript code to the landing page:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>

On one landing page, another snippet of code included (for a third-party, marketing reasons etc) caused an issue where a script wouldn’t work until we changed the placement from “Head” to “After Body Tag” even though it worked fine being placed in the head on two other landing pages! I’ve also noticed what seems to be an inconsistent load order for scripts, to which I haven’t had time to look into (but this could be due to differentiating jquery versions being specified now that I see Jess’s response above - I’m very curious why on some landing pages that does seem to matter, especially in the script order sense).

Then there was one, where we had to specifically define the version inline with the script:

I can say, tinker with the placement, if you need to merge some scripts into the same editor, that should be fine as well.

1 Like