Email validation using MATCH (RegEx)


#1

Hi All,
I tired to validate email ids using RegEx (using Match). The best I could come up so far is as follows:

Expression:
^[a-zA-Z0-9!#$%&\’+/=?^_{|}~-][a-zA-Z0-9!.#$%&\’*+/=?^_{|}~-][email protected][a-zA-Z0-9-]+{[?.]+[a-zA-Z0-9-]+}$

The above expression DOES NOT cater for the following email formats: (There could be more that I haven’t thought of)
[email protected]
[email protected]
[email protected]
[email protected]

Please share if you can optimise the above RegEx expression and/or if you have a way to deal with the email formats mentioned above?

I had an earlier post about Match (RegEx).

Thanks

Mathew


#2

I made a little progress from yesterday. I am also attaching the test program (C10 app) for anybody to try.

Revised Expression:
^[a-zA-Z0-9!#$%&\’+/=?^_{|}~-][a-zA-Z0-9!#$%&\’*+/=?^_{|}~-]+{[?.][a-zA-Z0-9!#$%&\’+/=?^_{|}~-]+}*@[a-zA-Z0-9-]+{[?.][a-zA-Z0-9-]+}*$

My test application looks like this:

MatchExpression.zip (765.8 KB)

Regards

Mathew


#3

I just use the following - not as complicated as yours so may not catch all but works for my needs

Notice I use UPPER to eliminate all the a-zA-Z duplication you have.

  IF ~MATCH(UPPER(wrkEmail),'^[-A-Z0-9.!#$%&''*+-/=?^_`{{|}~][email protected]{{[-A-Z0-9.]+\.}+[A-Z][A-Z]+$',Match:Regular)

#4

Thanks Kevin for the UPPER function suggestion. But, I didn’t realise that I am calling MATCH with MATCH:Regular + Match:NoCase as this test app was done a few years ago. Therefore a-zA-Z is already being ignored.

Took the last bit from your suggestion.

Latest Expression:
^[A-Z0-9!#$%&\’+/=?^_{|}~-][A-Z0-9!#$%&\’*+/=?^_{|}~-]+{[?.][A-Z0-9!#$%&\’+/=?^_{|}~-]+}*@[A-Z0-9-]+{[?.][A-Z0-9-]+}*[A-Z0-9]$

This validates all the emails I have in my list.

Thanks


#5

I have been using https://emailregex.com/ for a while for this, is working nicely.

See the big title about half way down the page. General Email Regex (RFC 5322 Official Standard)

Regards

Richard Bryce
www.nsitau.com