Reg ex for emails
Question

Good day


I have gone through the forum and nothing seems to work. I would like to use the Text Regex_Search method to validate an email. The pattern I passed in is 

RFC 5322 compliant:

\A[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*
@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\z

That I got from https://www.outsystems.com/forums/discussion/22928/how-to-validate-com-in-email/.

This keeps returning a false for every email.

I cant use the EmailAddressValidate() as this does not pick up on evrything. As david@gmail.co is valid according to this function.

Any help would be very much appreciated.


Kind regards 

Solution

Hi David,

I did some testing and it seems to work with this regex pattern:

(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\""""(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*\"""")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])

and the test results with your email addresses:

give it a try and share the results.


Cheers,

António Pereira


I would just like to add that I am using an excel file that I iterate trough. Each record has 5 emails.

EmailAddressValidate()  works to check the first email but fails the check on the second email. 

As example david@gmail.co wil return false as the first email but jack@gmail.co will return true if its the second email when using EmailAddressValidate()

Can you post an OML?

Solution

Hi David,

I did some testing and it seems to work with this regex pattern:

(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\""""(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*\"""")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])

and the test results with your email addresses:

give it a try and share the results.


Cheers,

António Pereira


So the problem is we actually that you can't validate an email this way. As the domain can be anything. Technically gmail.co should fail it should be .com. But after looking around you can use anything as a domain that is why as far as my understanding goes the check doesn't fail .co.

I unfortunately can't share an OML as this is on my workplace dev.  



Thank you
António Pereira

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.