Adding Custom Form Validation for a Full Name input field

  • 17 January 2017
  • 7 replies
  • 39 views

Userlevel 2
Badge +1

Hey guys,
I tried using the code below for a Full Name validation in a single input field with a space between the texts(a space between the first and second name). But for some reasons I couldn’t make it work! Will you please kindly have a look at it?

This is the code:

And this is my landing page: http://unbouncepages.com/pradaxa-one/

Thanks.


7 replies

Userlevel 7
Badge +3

Hi @Nayon,

The problem is with your regex validation rule. Currently, any single character would validate it.

I would strongly advise against validating Full Name since it would open you up to a world of edge cases.

However, if you still want to proceed just Google a proper full name regex validation.

Best,
Hristian

Userlevel 2
Badge +1

Hello Hristian,
Thanks for your quick response!
I understand the complexity with it but I still need to do it!

And I followed your suggestion of Googling it. And found this:

But I am not really a javascript guy! I don’t know how to put it in my above code. Will you please kindly help me here?

Userlevel 2
Badge +1

Actually I solved it! with this code:

Userlevel 7
Badge +3

Hi @Nayon,

I’m happy you’ve found a solution but like I said any regex checking a full name would open up dozens of edge cases.

Your current implementation doesn’t account for names having: hyphens (common in last names), more than 2 names, names with apostrophes and probably a bunch of other variations.

Best,
Hristian

Userlevel 2
Badge +1

Yeah, I totally understand why you told me not to go with it! But my client demanded even after hearing what complications it might bring in!
So, had to do it.

Thanks for you suggestions and replies man.

Badge

Hi @Nayon, Thank you for your great script. i used this script on a page where it works great. But on another page i added recently, is not working. Do you have solution For it.

Kind Regards
Bayzid

Userlevel 2
Badge +1

Hello Bayzid,
Glad that it worked for you. A lot has changed and updated on unbounce since I last used this script, so I am not sure if it’s conflicting with any new script updates.
Can you please share your page link?

Also,the script was made specifically to meet a certain condition I needed for my page. So, that might be another reason it worked on one of yours pages and not on the other!

Reply