Look... This will validate both external and internal addresses and domains.
That means that if you want to validate against all of the tld's out there
(which was one of my previous posts) you would need this regular expression
(Remember for all of the "."'s in the last bit, replace it with [.] as
otherwise it will see it as any character instead of a "."):
^[a-zA-Z0-9!##\$%&''\*\+-/=\?\^_`\{\|}~]+([.][a-zA-Z0-9!##\$%&''\*\+-/=\?\^_
`\{\|}~]+)*@([a-z0-9]([-]|[a-z0-9])*[a-z0-9][.])+(.ac|.ad|.ae|.af|.ag|.ai|.a
l|.am|.an|.a
o|.aq|.ar|.ar|.as|.at|.au|.aw|.az|.ba|.bb|.bd|.be|.bf|.bg|.bh|.bi|.biz|.
o|bj|.
bm|.bn|.bo|.br|.bs|.bt|.bv|.bw|.by|.bz|.ca|.cc|.cd|.cf|.cg|.ch|.ci|.ck|.
bm|cl|.
cm|.cn|.co|.coop|.com|.cr|.cu|.cv|.cy|.cx|.cz|.de|.dj|.dm|.do|.dk|.dz|.e
cm|c|.e
du|.ee|.eg|.eh|.er|.es|.et|.eu|.fi|.fk|.fm|.fo|.fr|.fx|.ga|.gd|.ge|.gf|.
du|gg|.
gh|.gi|.gl|.gm|.gn|.gov|.gp|.gq|.gr|.gs|.gt|.gu|.gy|.gw|.hm|.hn|.hk|.hr|
gh|.ht|
.hu|.id|.ie|.il|.im|.in|.info|.int|.io|.iq|.ir|.is|.it|.je|.jm|.jo|.jp|.ke|.
kg|.ki|.kid|.km|.kn|.kp|.kr|.ky|.kw|.kz|.la|.lb|.lc|.li|.lk|.lr|.ls|.lt|
kg|.lu|
.lv|.ly|.ma|.mc|.md|.mh|.mg|.mil|.mk|.ml|.mm|.mn|.mo|.mp|.mq|.mr|.ms|.mt|.mu
|.museum|.mv|.mw|.mx|.my|.mz|.na|.name|.nc|.ne|.net|.nf|.ng|.ni|.nl|.no|
|.np|
.nr|.nu|.nz|.om|.org|.pa|.pe|.pf|.pg|.ph|.pk|.pl|.pm|.pn|.pr|.pro|.pt|.pw|.p
y|.qa|.re|.ro|.ru|.rw|.sa|.sb|.sc|.sd|.se|.sg|.sh|.si|.sj|.sk|.sl|.sm|.s
y|n|.s
o|.sr|.st|.su|.sv|.sy|.sz|.tc|.td|.tf|.tg|.th|.tj|.tk|.tm|.tn|.to|.tp|.t
o|r|.t
t|.tv|.tw|.ua|.ug|.us|.uk|.um|.uy|.uz|.va|.vc|.ve|.vg|.vi|.vn|.vu|.wf|.w
t|s|.y
e|.yt|.yu|.za|.zm|.zw|.ad|.ae|.al|.am|.at|.az|.ba|.be|.bf|.bg|.bh|.bj|.b
e|y|.c
f|.ch|.ci|.cm|.cv|.cy|.cz|.de|.dj|.dk|.dz|.ee|.eg|.er|.es|.eu|.fi|.fo|.f
f|r|.g
a|.gb|.ge|.gg|.gh|.gi|.gn|.gq|.gr|.gw|.hr|.hu|.ie|.il|.im|.io|.iq|.ir|.i
a|s|.i
t|.je|.jo|.ke|.kg|.kz|.lb|.li|.lr|.lu|.lv|.ma|.mc|.md|.mk|.ml|.mt|.ne|.n
t|g|.n
l|.no|.om|.pl|.pt|.qa|.ro|.ru|.sa|.se|.si|.sj|.sk|.sl|.sm|.sn|.su|.sy|.t
l|d|.t
j|.tm|.tn|.tr|.ua|.ug|.uk|.uz|.va|.ye|.yu)&
You can sort out the word wrap yourselves! The only thing then is, internal
addresses will be invalid (but that's okay).
Paul
-------------------------------------------
Paul Johnston
PJ Net Solutions Ltd
http://www.pjnetsolutions.com
[EMAIL PROTECTED]
+44 (0)7866 573013
> -----Original Message-----
> From: Robertson-Ravo, Neil (RX)
> [mailto:[EMAIL PROTECTED]]
> Sent: 28 January 2003 13:51
> To: '[EMAIL PROTECTED]'
> Subject: RE: [ cf-dev ] Regular Expression for Email and
> Domain checking - it works!
>
>
> Its also not 100% correct as it will validate [EMAIL PROTECTED] as
> a correct email....
>
> and no, it states [EMAIL PROTECTED] is TRUE.
>
> N
>
> -----Original Message-----
> From: Paul Johnston [mailto:[EMAIL PROTECTED]]
> Sent: 28 January 2003 13:47
> To: [EMAIL PROTECTED]
> Subject: [ cf-dev ] Regular Expression for Email and Domain
> checking - it works!
>
>
> Everyone,
>
> For those that can't be bothered to read to the bottom here
> is the regular expression for validating an email address:
>
> ^[a-zA-Z0-9!##\$%&''\*\+-/=\?\^_`\{\|}~]+([.][a-zA-Z0-9!##\$%&
> ''\*\+-/=\?\^_
> `\{\|}~]+)*@([a-z0-9]([-]|[a-z0-9])*[a-z0-9][.])+(([a-z0-9]([-
> ]|[a-z0-9])*[a
> -z0-9])|com|co[.]uk|net|org|com[.]uk)$
>
> Having read the various RFC's around the place about domains
> and emails, I just thought I'd let you know what I'd found out!
>
> Here is the regular expression for validating the part before
> an @ in an email address:
>
> [a-zA-Z0-9!#$%&'*+-/=?^_`{|}~]+([.][a-zA-Z0-9!#$%&'*+-/=?^_`{|}~]+)*
>
> Basically, according to RFC 2822 (and I haven't checked
> what's updated it yet, so this may still be incomplete), this
> is the form that an address must take before the @ sign. It
> starts with either a digit or a number, or one of the other
> characters in there, and then can include a period, but must
> end in one of those characters (ie not in a period). There
> are 2 other forms of email address, but they are mainly for
> use internally within a mailserver (and are unimportant in
> terms of functionality of the regex) and it should be no
> problem to ignore them.
>
> My previous email outlined the regular expression for
> validating a domain name (simple form):
>
> ([a-z0-9]([-]|[a-z0-9])*[a-z0-9][.])+(([a-z0-9]([-]|[a-z0-9])*
> [a-z0-9])|com|
> co[.]uk|net|org|com[.]uk)
>
> And you can create a regular expression for validating
> emails. Please note, that none of this is tested, although
> it does look okay to me ;). The regular expression then for
> testing if an email is valid is:
>
> [a-zA-Z0-9!#$%&'*+-/=?^_`{|}~]+([.][a-zA-Z0-9!#$%&'*+-/=?^_`{|
> }~]+)*@([a-z0-
> 9]([-]|[a-z0-9])*[a-z0-9][.])+(([a-z0-9]([-]|[a-z0-9])*[a-z0-9
> ])|com|co[.]uk
> |net|org|com[.]uk)
>
> (NOTE: watch the word wrap)
>
> Bearing in mind that CF needs to escape several of the
> characters in the regular expression, it becomes this:
>
> [a-zA-Z0-9!##\$%&''\*\+-/=\?\^_`\{\|}~]+([.][a-zA-Z0-9!##\$%&'
> '\*\+-/=\?\^_`
> \{\|}~]+)*@([a-z0-9]([-]|[a-z0-9])*[a-z0-9][.])+(([a-z0-9]([-]
> |[a-z0-9])*[a-
> z0-9])|com|co[.]uk|net|org|com[.]uk)
>
> And also taking into account that you need to check the whole
> string, ie this must be from the start to the end, you get:
>
> ^[a-zA-Z0-9!##\$%&''\*\+-/=\?\^_`\{\|}~]+([.][a-zA-Z0-9!##\$%&
> ''\*\+-/=\?\^_
> `\{\|}~]+)*@([a-z0-9]([-]|[a-z0-9])*[a-z0-9][.])+(([a-z0-9]([-
> ]|[a-z0-9])*[a
> -z0-9])|com|co[.]uk|net|org|com[.]uk)$
>
> You can easily make this into a function or into a custom
> tag. In fact, I'll be nice and write the function for you:
>
> <cfscript>
> // returns true or false depending on whether or not it's
> valid function isValidEmail(emailstr) {
> regex =
> "^[a-zA-Z0-9!##\$%&''\*\+-/=\?\^_`\{\|}~]+([.][a-zA-Z0-9!##\$%
> &''\*\+-/=\?\^
> _`\{\|}~]+)*@([a-z0-9]([-]|[a-z0-9])*[a-z0-9][.])+(([a-z0-9]([
> -]|[a-z0-9])*[
> a-z0-9])|com|co[.]uk|net|org|com[.]uk)$";
> if(REFind(regex, emailstr)) {
> return true;
> }
> else
> return false;
> }
> </cfscript>
>
> (NOTE: watch the word wrap again)
>
> I hope this helps you all sort your email addresses out okay now!
>
> Paul
> -------------------------------------------
> Paul Johnston
> PJ Net Solutions Ltd
> http://www.pjnetsolutions.com
> [EMAIL PROTECTED]
> +44 (0)7866 573013
>
>
>
>
> --
> ** Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/
>
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED] For human help, e-mail:
> [EMAIL PROTECTED]
>
> --
> ** Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/
>
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED] For human help, e-mail:
> [EMAIL PROTECTED]
>
>
>
--
** Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
For human help, e-mail: [EMAIL PROTECTED]