# Email validation using MATCH (RegEx)

**URL:** <https://clarionhub.com/t/email-validation-using-match-regex/1992>\
**Category:** questions\
**Created:** [July 19, 2018, 10:43am UTC](https://clarionhub.com/t/email-validation-using-match-regex/1992 "2018-07-19T10:43:33Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mathew](https://clarionhub.com/letter_avatar_proxy/v4/letter/m/5daacb/32.png) [@Mathew](https://clarionhub.com/u/Mathew)\
**Post date:** [July 19, 2018, 10:43am UTC](https://clarionhub.com/t/email-validation-using-match-regex/1992/1 "2018-07-19T10:43:33Z")

</div>

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

Expression:  
\[1\]+@[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)**  
[name.@domain.com](mailto:name.@domain.com)  
[name..surname@domain.com](mailto:name..surname@domain.com)  
name.surname@domain.c  
name.surname@domain.1a

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](https://clarionhub.com/t/match-function-is-not-working-to-my-requirement/338) about Match (RegEx).

Thanks

Mathew

* * *

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

---

<div class="post-metadata">

**Author:** ![Mathew](https://clarionhub.com/letter_avatar_proxy/v4/letter/m/5daacb/32.png) [@Mathew](https://clarionhub.com/u/Mathew)\
**Post date:** [July 20, 2018, 10:24am UTC](https://clarionhub.com/t/email-validation-using-match-regex/1992/2 "2018-07-20T10:24:09Z")

</div>

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:

 ![image](https://clarionhub-uploads.s3.dualstack.eu-north-1.amazonaws.com/original/2X/a/ab65806854f91c909db667dd9b4f1a02e6566a7a.png)

[MatchExpression.zip](https://clarionhub-uploads.s3.dualstack.eu-north-1.amazonaws.com/original/1X/8a4ec4b8c54104b268f8abc528f20939fa2b2fcb.zip) (765.8 KB)

Regards

Mathew

---

<div class="post-metadata">

**Author:** ![KevinErskine](https://clarionhub.com/user_avatar/clarionhub.com/kevinerskine/32/711_2.png) [@KevinErskine](https://clarionhub.com/u/KevinErskine)\
**Post date:** [July 22, 2018, 5:18pm UTC](https://clarionhub.com/t/email-validation-using-match-regex/1992/3 "2018-07-22T17:18:29Z")

</div>

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.!#$%&''*+-/=?^_`{{|}~]+@{{[-A-Z0-9.]+\.}+[A-Z][A-Z]+$',Match:Regular)

```

---

<div class="post-metadata">

**Author:** ![Mathew](https://clarionhub.com/letter_avatar_proxy/v4/letter/m/5daacb/32.png) [@Mathew](https://clarionhub.com/u/Mathew)\
**Post date:** [July 23, 2018, 7:22am UTC](https://clarionhub.com/t/email-validation-using-match-regex/1992/4 "2018-07-23T07:22:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Richard](https://clarionhub.com/user_avatar/clarionhub.com/richard/32/368_2.png) [@Richard](https://clarionhub.com/u/Richard)\
**Post date:** [December 7, 2018, 3:11am UTC](https://clarionhub.com/t/email-validation-using-match-regex/1992/5 "2018-12-07T03:11:02Z")

</div>

I have been using [https://emailregex.com/](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

> **[North Shore I.T. Services Pty Limited - Home](http://www.nsitau.com)**
>
> Located Sydney NSW Australia we are business software custom design and development consultants. We provide end to end information technology consulting services

---

<div class="post-metadata">

**Author:** ![Clarion\_clarion](https://clarionhub.com/user_avatar/clarionhub.com/clarion_clarion/32/636_2.png) [@Clarion\_clarion](https://clarionhub.com/u/Clarion_clarion)\
**Post date:** [July 8, 2020, 9:06am UTC](https://clarionhub.com/t/email-validation-using-match-regex/1992/6 "2020-07-08T09:06:29Z")

</div>

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

but it will validate **[a.name@asdf.com](mailto:a.name@asdf.com)** as invalid (so 1 char A before dot)  
but **[aa.name@asdf.com](mailto:aa.name@asdf.com)** is OK (two AA before dot).

I am not an expert in Regex so could anyone give me the correct syntax, please?

tried this but it doesn’t work  
`^[A-Z0-9!#$%&'*+/=?^_'{|}~-]+(?:\.[A-Z0-9!#$%&'*+/=?^_'{|}~-]+)*@(?:[A-Z0-9](?:[A-Z0-9-]*[A-Z0-9])?\.)+[A-Z0-9](?:[A-Z0-9-]*[A-Z0-9])?$`

* * *

1. A-Z0-9!#$%&\’+/=?^\_{|}~-

---

<div class="post-metadata">

**Author:** ![Mike\_Duglas](https://clarionhub.com/user_avatar/clarionhub.com/mike_duglas/32/1061_2.png) [@Mike\_Duglas](https://clarionhub.com/u/Mike_Duglas)\
**Post date:** [July 8, 2020, 7:25pm UTC](https://clarionhub.com/t/email-validation-using-match-regex/1992/7 "2020-07-08T19:25:21Z")

</div>

You will have enough time to solve the issue on the vacations 🙂

---

<div class="post-metadata">

**Author:** ![Clarion\_clarion](https://clarionhub.com/user_avatar/clarionhub.com/clarion_clarion/32/636_2.png) [@Clarion\_clarion](https://clarionhub.com/u/Clarion_clarion)\
**Post date:** [August 3, 2020, 9:17am UTC](https://clarionhub.com/t/email-validation-using-match-regex/1992/8 "2020-08-03T09:17:43Z")

</div>

any idea how to fix it?

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [August 4, 2020, 5:05pm UTC](https://clarionhub.com/t/email-validation-using-match-regex/1992/9 "2020-08-04T17:05:46Z")

</div>

> Match:NoCase … Therefore a-zA-Z is already being ignored.

I’m pretty certain Match:NoCase only applies outside of [sets] so [A-Za-z] is required to match both upper and lower case letters. The easier way for NoCase is to UPPER(email) as Kevin had so you only need sets with [A-Z]

I wonder about this part: {[?.][A-Z0-9-]+}

You’re saying an email can have a [Question Mark or Period] once, then [Letters/Numbers/Dash] 1 or more times?  
An email can use a ? in the Domain instead of a Period?

Maybe [?.] would be more correct as a Backslash-Period an Escaped Period to indicate a Period?

I thought domains always ended with Period 2+ letters or numbers like .com or .co.uk: .[A-Z0-9][A-Z0-9]+

---

<div class="post-metadata">

**Author:** ![Clarion\_clarion](https://clarionhub.com/user_avatar/clarionhub.com/clarion_clarion/32/636_2.png) [@Clarion\_clarion](https://clarionhub.com/u/Clarion_clarion)\
**Post date:** [August 5, 2020, 7:14am UTC](https://clarionhub.com/t/email-validation-using-match-regex/1992/10 "2020-08-05T07:14:01Z")

</div>

Carl,  
Thank you for your answer.

I am talking about MatchExpression.zip example (attached here) and RegEx expression used there. So the problem is that using this regex string **Latest Expression** (see above)

but it will validate **[a.name@asdf.com](mailto:a.name@asdf.com)** as invalid (so 1 char A before dot)  
but **[aa.name@asdf.com](mailto:aa.name@asdf.com)** is OK (two AA before dot).

and of course, I am using MATCH(UPPER(wrkEmail)…

So I am not sure what is wrong with regex above to validate email like [a.name@asdf.com.uk](mailto:a.name@asdf.com.uk)

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [August 5, 2020, 5:56pm UTC](https://clarionhub.com/t/email-validation-using-match-regex/1992/11 "2020-08-05T17:56:05Z")

</div>

My questions is why you have [?.]

> [@Clarion\_clarion](#):
>
> but it will validate **[a.name@asdf.com](mailto:a.name@asdf.com)** as invalid (so 1 char A before dot)  
> but **[aa.name@asdf.com](mailto:aa.name@asdf.com)** is OK (two AA before dot).

That’s easy if you look at your expression split into parts like below in line 2 it requires 1 character from the set [a-z] , plus line 3 requires “+” (1 or more) from the next set ([a-z]+) so you require 2 before any period (or question mark)

```
1. ^
2. [A-Z0-9!#$%&\’+/=?^{|}~-]
3. [A-Z0-9!#$%&\’+/=?^{|}~-*]+
4. {[?.][A-Z0-9!#$%&\’+/=?^_{|}~-]+}
5. @
6. [A-Z0-9-]+
7. {[?.][A-Z0-9-]+}
8. [A-Z0-9]
9. $

```

I do not have the Email spec memorized and this is a complicated expression, maybe too complicated. Are trying to prevent invalid use of the period like .. @. .@ ? I would do that separately. This is untested:

```
IF MATCH('^\.|\.$',Eml,Match:Regex) THEN ! No .billg@m
    Message('Cannot begin or end with a period')
...
P=STRPOS('\.\.|\.@|@\.',Eml) ! No .. .@ @.
IF P THEN 
  MESSAGE('Invalid Period at position ' & P & ': ' & SUB(Eml,P,2)
…

```

Maybe then your expression before the @ can be simpler.

I would suggest on your Window you add a TEXT control so you can work on the separate lines more easily (like my 1 to 9 above). PROP:LineCount and PROP:Line can be used to get the lines and concat into a single string.

In sets the hyphen should be first so [A-Z0-9-] as [-A-Z0-9]

Below worked for me, except it does not catch the .. .@ that I would do separately. I added Underscore. Not sure why you have ? or . so changed [?.] to backslash-period. Is Name@Domain with no .xx suffix valid?

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

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

```

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [August 5, 2020, 6:23pm UTC](https://clarionhub.com/t/email-validation-using-match-regex/1992/12 "2020-08-05T18:23:48Z")

</div>

If this will be used to tell a user Message(‘Email entry is invalid’) I would split checking into parts so messages make it obvious where the problem is so you don’t create puzzle for the user nor tech support.

Tell them they have a space at position X. You could just quietly take out spaces but I wouldn’t.  
Check for a single @  
Check for invalid periods  
Validate before the @  
Validate after the @

---

<div class="post-metadata">

**Author:** ![Clarion\_clarion](https://clarionhub.com/user_avatar/clarionhub.com/clarion_clarion/32/636_2.png) [@Clarion\_clarion](https://clarionhub.com/u/Clarion_clarion)\
**Post date:** [August 6, 2020, 6:49am UTC](https://clarionhub.com/t/email-validation-using-match-regex/1992/13 "2020-08-06T06:49:56Z")

</div>

> [@CarlBarnes](#):
>
> My question is why you have [?.]

😀 It’s not I have it - this was original regex from the attached example. Honestly speaking I have no idea how does regex work and used example in my project.

Thank you for your detailed answer - I will follow it and try to figure out

---

<div class="post-metadata">

**Author:** ![Clarion\_clarion](https://clarionhub.com/user_avatar/clarionhub.com/clarion_clarion/32/636_2.png) [@Clarion\_clarion](https://clarionhub.com/u/Clarion_clarion)\
**Post date:** [August 12, 2020, 10:54am UTC](https://clarionhub.com/t/email-validation-using-match-regex/1992/14 "2020-08-12T10:54:53Z")

</div>

Is there any other way to validate Email address?

---

<div class="post-metadata">

**Author:** ![Mike\_Duglas](https://clarionhub.com/user_avatar/clarionhub.com/mike_duglas/32/1061_2.png) [@Mike\_Duglas](https://clarionhub.com/u/Mike_Duglas)\
**Post date:** [August 12, 2020, 12:34pm UTC](https://clarionhub.com/t/email-validation-using-match-regex/1992/15 "2020-08-12T12:34:19Z")

</div>

> <https://stackoverflow.com/questions/46155/how-can-i-validate-an-email-address-in-javascript>

---

<div class="post-metadata">

**Author:** ![Rudik](https://clarionhub.com/letter_avatar_proxy/v4/letter/r/439d5e/32.png) [@Rudik](https://clarionhub.com/u/Rudik)\
**Post date:** [July 27, 2022, 9:14am UTC](https://clarionhub.com/t/email-validation-using-match-regex/1992/16 "2022-07-27T09:14:13Z")

</div>

Hi Mathew,

I left your match() as it is and simply fixed the 1-letter problem by adding an extra letter, just for the check:

old: match(upper(  
new: match(‘A’&upper(

The whole thing then looks like this… and works perfectly

match(‘A’&upper(clip(DEB:EMAIL)),‘\[1\][A-Z0-9!#$%&\’_+/=?^{|}~-]+{[?.][A-Z0-9!#$%&\’+/=?^{|}~-]+}_@[A-Z0-9-]+{[?.][A-Z0-9-]+}\*[A-Z0-9]$’, Match:Regular)

HTH  
Rudolf

* * *

1. A-Z0-9!#$%&\’+/=?^\_{|}~-

---

<div class="post-metadata">

**Author:** ![KevinErskine](https://clarionhub.com/user_avatar/clarionhub.com/kevinerskine/32/711_2.png) [@KevinErskine](https://clarionhub.com/u/KevinErskine)\
**Post date:** [July 30, 2022, 4:45pm UTC](https://clarionhub.com/t/email-validation-using-match-regex/1992/17 "2022-07-30T16:45:47Z")

</div>

This is what I use and have never had a problem - it differs from yours in 4 places

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

1 - +/=?^{|} I have +/=?^_{|} – Notice \_ after the ^  
2 - +/=?^{|} I have +/=?^_{|} – Notice \_ after the ^  
3 - ]+}@[A- I have]+}_@[A- – Notice \* after the }  
4 - ]+}[A-Z I have]+}_[A-Z – Notice \* after the }

* * *

1. A-Z0-9!#$%&'+/=?^\_{|}~-

---

<div class="post-metadata">

**Author:** ![Rudik](https://clarionhub.com/letter_avatar_proxy/v4/letter/r/439d5e/32.png) [@Rudik](https://clarionhub.com/u/Rudik)\
**Post date:** [August 1, 2022, 9:58am UTC](https://clarionhub.com/t/email-validation-using-match-regex/1992/18 "2022-08-01T09:58:54Z")

</div>

> [@KevinErskine](#):
>
> \[1\][A-Z0-9!#$%&’_+/=?^_ {|}~-]+{[?.][A-Z0-9!#$%&’+/=?^\_{|}~-]+} _@[A-Z0-9-]+{[?.][A-Z0-9-]+}_ [A-Z0-9]$

Hi Kevin,

thanks, but with your variant I get a lot of invalid email addresses, even though they are allowed like the following:

a@bbb.ccc = false  
ab@bbb.ccc = false  
a.b@bbb.ccc = false  
info@test.ccc = false  
a.info@test.ccc = false  
ab.info@test.ccc = true

Perhaps you have published the wrong variant? or characters were lost during copy&paste?

Cheers  
Rudolf

* * *

1. A-Z0-9!#$%&’+/=?^ \*{|}~-

---

<div class="post-metadata">

**Author:** ![KevinErskine](https://clarionhub.com/user_avatar/clarionhub.com/kevinerskine/32/711_2.png) [@KevinErskine](https://clarionhub.com/u/KevinErskine)\
**Post date:** [August 1, 2022, 8:17pm UTC](https://clarionhub.com/t/email-validation-using-match-regex/1992/19 "2022-08-01T20:17:56Z")

</div>

OOPs I did post the wrong string — sorry - this works

‘\[1\]+@{{[-A-Z0-9.]+.}+[A-Z][A-Z]+$’

 ![Screenshot 2022-08-01 131320](https://clarionhub-uploads.s3.eu-north-1.amazonaws.com/original/2X/9/94d6020eb74c0a6e5ccc8aeabe6cb462754e10f2.jpeg)

* * *

1. -A-Z0-9.!#$%&‘’\*±/=?^\_`{{|}~

---

<div class="post-metadata">

**Author:** ![KevinErskine](https://clarionhub.com/user_avatar/clarionhub.com/kevinerskine/32/711_2.png) [@KevinErskine](https://clarionhub.com/u/KevinErskine)\
**Post date:** [August 1, 2022, 8:14pm UTC](https://clarionhub.com/t/email-validation-using-match-regex/1992/20 "2022-08-01T20:14:34Z")

</div>

I am sorry I did indeed post the wrong MATCH string

IF ~MATCH(UPPER(wrkEmail),'\[1\]+@{{[-A-Z0-9.]+.}+[A-Z][A-Z]+$',Match:Regular)

 ![image001.png](https://clarionhub-uploads.s3.eu-north-1.amazonaws.com/original/2X/d/d695f3daaaf2e32da59ba36a611d072ff6c2ce39.png)

Kevin Erskine

Ragazzi Enterprise, LLC

415.819.1415

_Communication is the key to a successful relationship._

* * *

1. -A-Z0-9.!#$%&‘’\*±/=?^\_`{{|}~

[Next page](https://clarionhub.com/t/email-validation-using-match-regex/1992.md?page=2)
