Custom validation to ensure that text entry email address contains specific domain | XM Community
Question

Custom validation to ensure that text entry email address contains specific domain

  • 26 February 2020
  • 1 reply
  • 187 views

Userlevel 1
Badge +2
I have a text entry field where users enter an email address. The email address must always end with "@bsu.edu" and include between 3 and 12 characters (letters and numbers) for the username portion. The username cannot contain any special characters or symbols. I presume I will need to use RegEx to check for valid email addresses but I'm having difficult understanding how to write an appropriate RegEx pattern.

I have written the following pattern but the validation still passes when a user can enter more than 12 characters/numbers before the "@bsu.edu"

/^[A-Z0-9]{3,12}(@bsu.edu)$/gi

What am I missing that limit the character/digit count for the username portion to a maximum 12 characters/numbers?

1 reply

Userlevel 5
Badge +15
Hi @ambrubaker I can't replicate this issue. When I use your RegEx code on a sample survey of mine, it is catching emails with >12 characters in the username. Your code also works when I test it on this RegEx tester: https://regex101.com/

The only thing that occurs to me is that if you previously didn't have this applied, maybe saved browser settings are allowing this to pass? I'd try clearing your history and cookies and re-test. Maybe also send the survey to a colleague to see if they can replicate the issue?

Leave a Reply