Regex for validating mail adresses

Within textfields it is possible to use regex. Here is one that checks for email adresses:

^[a-zA-Z0-9_.±]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+

Could anyone tell me if this is correct?

with the mail adress: support@nethinks.com it works :wink:

If you want to develop new regex or want to check if yours are working: use: https://regex101.com

1 Like

Hi @uwe ,

thanks for sharing your regex. Seems, you like this feature and you remind me of extending it with a set of predefined regular expressions for things like IP addresses, hostnames, e-mail, and so on. I opened a task on our roadmap:

  • [NET-328] Add predefined regular expressions for textfie-lds

A few minutes ago, I discussed that with our development team and we will time that feature for our next Sprint to have it available in our next release 1.1.0.

Do you have any suggestions of which predefined regex we should add?

For now I would appreciate the following:

  • IP-Address v4
  • IP-Address v6
  • email addresses
  • URL
  • Phone-Numbers (it would be nice if they would be “beautified”-> 0049661250000 extends automatically to +49 661 25000 0)

Hello,

regex for url and email addresses are complex. @uwe, yours for email seems fine for many cases, but apparently more special characters can be used in valid addresses (cf. RFC 5322).

Fortunately there are some resources like regular-expressions.info who already did the dirty work and they seem to settle on the following regex (excluding some things like IP-addresses and other specific cases):

\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

(… assuming this gets escaped well, otherwise: see reference below)

The complete regex can also be found on their site. Since Datagerry aims to be enterprise-level this complete regex may be useful, because organisations sometimes get creative with naming.

Ref: https://www.regular-expressions.info/email.html

1 Like

Thank you. I also just googled the regex. Your link is very helpful