473,718 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Email address regular expression

I've been using this pattern to verify email addresses:

^([0-9a-z]+)([0-9a-z\.-_]+)@([0-9a-z\.-_]+)\.([0-9a-z]+)

But I've recently discovered that addresses with a dash in them won't
pass this test.

Seems to me they should pass.

What's wrong?

--
Floydian Slip(tm) - "Broadcasti ng from the dark side of the moon"
Random Precision Productions(tm)
67 Union St. #2D, Winooski, Vt. 05404-1948 USA
Sundays, 7-8 pm - Champ 101.3 FM, Colchester; 102.1 FM, Randolph, Vt.
cc*@floydiansli p.com - AIM: RandomPrec - www.floydianslip.com
Jul 17 '05 #1
11 7656
Craig Bailey wrote:
I've been using this pattern to verify email addresses:

^([0-9a-z]+)([0-9a-z\.-_]+)@([0-9a-z\.-_]+)\.([0-9a-z]+)

But I've recently discovered that addresses with a dash in them won't
pass this test.

Seems to me they should pass.


[A-Z] = All characters from A to Z, maybe a \- might help ?

--
Spam:newsgroup( at)cr*********@ verisign-sux-klj.com
EMail:<01100011 001011100110001 001110101011100 10011010110
110010101000000 011000110111001 001100001011110 10011011100
110000101110010 001011100110001 101101111011011 0100100000>
Jul 17 '05 #2
In article <Qp************ *********@news-server.bigpond. net.au>,
"127.0.0.1" <newsgroup(at)c r*********@veri sign-sux-ijlkl.com> wrote:
Craig Bailey wrote:
I've been using this pattern to verify email addresses:

^([0-9a-z]+)([0-9a-z\.-_]+)@([0-9a-z\.-_]+)\.([0-9a-z]+)

But I've recently discovered that addresses with a dash in them won't
pass this test.

Seems to me they should pass.


[A-Z] = All characters from A to Z, maybe a \- might help ?


Aaaahhhh. But a dash doesn't need to be escaped, do it? Are you
suggesting a add a dash to the first part of the expression? Like this?

^([0-9a-z-]+)([0-9a-z\.-_]+)@([0-9a-z\.-_]+)\.([0-9a-z]+)

Of course, that would allow someone to start their address with a dash,
which I'm not certain is allowable in real email addresses.

--
Floydian Slip(tm) - "Broadcasti ng from the dark side of the moon"
Random Precision Productions(tm)
67 Union St. #2D, Winooski, Vt. 05404-1948 USA
Sundays, 7-8 pm - Champ 101.3 FM, Colchester; 102.1 FM, Randolph, Vt.
cc*@floydiansli p.com - AIM: RandomPrec - www.floydianslip.com
Jul 17 '05 #3
[ not posted to alt groups ]

Craig Bailey wrote:
I've been using this pattern to verify email addresses:

^([0-9a-z]+)([0-9a-z\.-_]+)@([0-9a-z\.-_]+)\.([0-9a-z]+)

But I've recently discovered that addresses with a dash in them won't
pass this test.

Seems to me they should pass.

What's wrong?


Doesn't [0-9a-z\.-_] mean: 0 to 9 and a to z and dot to underscore?

try [0-9a-z\._-]
HTH

--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.
Jul 17 '05 #4
Hello,

On 10/06/2003 07:16 AM, Craig Bailey wrote:
I've been using this pattern to verify email addresses:

^([0-9a-z]+)([0-9a-z\.-_]+)@([0-9a-z\.-_]+)\.([0-9a-z]+)

But I've recently discovered that addresses with a dash in them won't
pass this test.

Seems to me they should pass.

What's wrong?


Character ranges that include - must start with that character. Take a
look here at this e-mail address validation class that comes with a
suitable regular expression besides the server based e-mail verification
methods.

http://www.phpclasses.org/emailvalidation
--

Regards,
Manuel Lemos

Free ready to use OOP components written in PHP
http://www.phpclasses.org/

Jul 17 '05 #5
Pedro wrote:
Doesn't [0-9a-z\.-_] mean: 0 to 9 and a to z and dot to underscore?
Yep. That's dot to underscore in "ASCII collating sequence". "Dot
to underscore" matches fifty characters in total, including all
uppercase letters, numbers, and a bunch of others -- but not the
hyphen!
try [0-9a-z\._-]


Or even [\w.-]. ;-)

--
Jock
Jul 17 '05 #6
Craig Bailey wrote:
Aaaahhhh. But a dash doesn't need to be escaped, do it?
Not necessarily. But in its current position, yes, because it's
indicating a range. The *hyphen* may only be left unescaped "where
it cannot be interpreted as indicating a range".
Of course, that would allow someone to start their address with a dash,
which I'm not certain is allowable in real email addresses.


I am certain it is.

See RFC 2822 for details, especially section 3.4.1.

--
Jock
Jul 17 '05 #7
On Mon, 06 Oct 2003 11:56:14 -0300, Manuel Lemos <ml****@acm.org > wrote:
Character ranges that include - must start with that character.


Or end with it.

--
Andy Hassall (an**@andyh.co. uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 17 '05 #8
John Dunlop wrote:
Or even [\w.-]. ;-)


that will match (in some locales) "josécuña"

ps. hope that gets out ok, in HTML I'd write it as
jos&eacute;cu&n tilde;a

--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.
Jul 17 '05 #9
Pedro wrote:
John Dunlop wrote:
Or even [\w.-]. ;-)
that will match (in some locales) "josécuña"


Ah. Well spotted! I forgot what the intended use was, and
concentrated on the one part. Thanks.
ps. hope that gets out ok


It did.

--
Jock
Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

117
11854
by: Steevo | last post by:
Any suggestions as to the best programs for cloaking email addresses? Many thanks -- Steevo
5
3109
by: Ryan | last post by:
HELLO I am using the following MICROSOFT SUGGESTED (somewhere on msdn) regular expression to validate email addresses however I understand that the RFP allows for "+" symbols in the email address and this method does not.... Does anyone have an explanation? Function IsValidEmail(ByVal strIn As String) As Boolean
35
3353
by: Mika M | last post by:
Simple question: Does Framework (1.1) contain any routine to check entered email-address is valid ? It's quite easy to make own code for that purpose, but why to do if Framework (1.1) contain this kind of routine. -- Thanks in advance! Mika
4
1413
by: Nick Bell | last post by:
The expression: preg_match_all("/text.*?(+@+\.{2,6})/i",$f, $matches); Returns ONE email address on a line in $f beginning 'text' - how do I retrieve ALL the email addresses on a line in $f beginning 'text' in php? Many thanks
1
1950
by: Jim Dornbush | last post by:
Has anyone seen an updated regex expression from Microsoft for the email validation expression so that single quotes are allowed? I've been using the canned regex for emails, but recently been informed by a customer that the single quote is allowed as part of the email address (Mr. O'Leary). I prefer using the un-modified version from the framework, but will update my local code regardless.
2
1828
by: Lad | last post by:
Did anyone try to find out a regular expression for finding an email address in a text? Thank you for the reply L.
12
4861
by: ll | last post by:
I am trying to finalize a regular expression in javascript to only allow emails with a certain domain to be valid. Here is what I have so far: var emailFilter2=/\@aol.com/; if(!(emailFilter2.test(strng))) { error = "Please enter a valid email address with the AOL domain.\n \n"; }
9
1895
by: chadlupkes | last post by:
I have this code from someone else, and I'm trying to make heads or tails of it because IE doesn't like it. Can anyone help? Or does anyone have a better idea? /* parse the email to check for valid form */ function parseemail(str) { str = trim(str); <?if(preg_match("/MSIE 5.0;/", $_SERVER)) // this is IE 5.0
10
30262
by: ll | last post by:
Hi, I currently am using the following regex in js for email validation, in which the email addresses can be separated by commas or semicolons. The problem, however, lies in that I can type two emails (as a run-on, with no comma or semicolon), and as long as it ends in a three character domain, it is accepted as valid. I wonder if there would be a way to make the comma or semicolon mandatory if a second email address existed? Many...
5
1871
by: Ganesh | last post by:
Hi There, I need to validate email address with regular expression control, i tried something like this ^+*@*\.*$ but i need to validate even if it is blank, it should say invalid email, but don't want to use another requirefield validator
0
8724
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9358
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9208
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9053
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7991
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6654
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5971
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4481
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2123
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.