Ensuring your forms capture high-quality leads can be challenging when users enter personal email addresses like Gmail or Yahoo. This step-by-step guide will show you how to validate email fields in Unbounce to ensure:
- Users are prompted to use a work email address.
- The form shows an error message if the email domain is invalid.
- Users can proceed after being prompted once, even with a personal email.
Why I Created This Solution
A while back, someone in the Unbounce community posed a question: “How can we ensure people use work emails instead of personal ones like Gmail, without completely blocking submissions?”
Their concern was valid—marketers want leads that are tied to businesses, not just casual browsers. However, most solutions were too rigid, forcing strict validations that could frustrate users.
This inspired me to create a more flexible approach. The solution I’m sharing here combines regex validation with dynamic JavaScript to strike a balance between quality and user experience.
Step 1: Set Up Your Email Field in Unbounce
Step 2: Add Custom Validation for Regex
Select the email field.
Under the Validation section, enable the
Custom Validation
option.Paste the following regex:
^(?!.*@(gmail\.com|yahoo\.com|hotmail\.com)$).+@.+\..+$
This ensures Unbounce blocks personal email domains like Gmail, Yahoo, or Hotmail.
You can also update the message under the “Validation Error Message” field.
Step 3: Add JavaScript for Dynamic Behavior
- Click on the Javascripts tab in the editor (bottom left corner).
- Add a new script and paste the following code:
- The code placement setting should be “Before the Body End”.
This script dynamically validates email addresses. Users will see an error message only on the first invalid submission.
Step 4: Test Your Form
- Preview your Unbounce page.
- Enter a personal email like test@gmail.com. You should see an error message prompting you to use a work email.
- Enter a valid email like user@company.com. The form should proceed without issues.
- Retry with a personal email after the first invalid attempt. It should allow submission.
Bonus Tip: Customize the Error Message
To personalize the user experience, you can update the error message text in the script:
const errorMessage = 'Please use your company email to proceed.';
Conclusion
This solution is perfect for marketers who want high-quality business leads without frustrating users. The combination of regex and JavaScript ensures invalid emails are flagged while giving users the flexibility to proceed after the first prompt.
If you want to supercharge your Unbounce pages with modern, refreshing templates that save time and maximize conversions, visit TemplatesForest.com.
We offer over 70+ customizable Unbounce templates designed for your needs. Transform your landing pages today!
Let me know your thoughts or share your own hacks in the comments below!
To get 14-Days FREE trial and 20% OFF for the first 3 months on your Unbounce account, please click here.