Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Please evaluate: RegEx for validating e-mail addresses

by DaWolf (Curate)
on Sep 27, 2004 at 11:44 UTC ( #394126=note: print w/replies, xml ) Need Help??


in reply to Re: Please evaluate: RegEx for validating e-mail addresses
in thread Please evaluate: RegEx for validating e-mail addresses

Hi, jdalbec. Thanks for replying.

Please use <code> tags around Perl code so it displays correctly.

Actually I used, but since the <code> tags are inside a <ol> tag maybe they aren't displaying correctly...

You may want to use (?: ... ) for grouping so you don't get a bunch of assignments to $1, $2, etc.

True, thanks for pointing this out.

Also {1} is redundant.

Also true. Thanks again, but...

In several cases your comments don't match what the regexp is doing.

Actually I've made a lot of testing and apparently it is... Could you clarify this part a little? I'm curious.

In 2. the (\.)+ allows two or more dots in a row. I think you probably just want to drop the + (and the redundant parentheses).

and

In 3. you have almost the same problem. Try changing * to ? unless you mean to allow multiple dashes/underscores in a row.

Actually I want to allow multiple dots, dashes and underscores since 'er.galvao.abbott@somedomain.com' or 'er_galvao_abbott@somedomain.com' are valid addresses.

In 9. I think you want (?:\.(?:[a-z0-9]){2,})*. I'm leaving the * (even though you said "possibly") since I think you can have any number of domain levels in a FQDN.

Thanks, I'll give this chunk a try and see what happens.

Thanks a lot for your reply,

Replies are listed 'Best First'.
Re^3: Please evaluate: RegEx for validating e-mail addresses
by jdalbec (Deacon) on Sep 30, 2004 at 01:51 UTC
    merlyn says please stop encouraging DaWolf - he's heading down a dangerous path
    It's true that you're heading down a dangerous path. Whatever regex you finally come up with, please don't use it in a production application. Use Email::Valid on the server and don't try to do complex processing in JavaScript.

    What is the application you want to validate e-mail addresses for? Do you only care that they're syntactically valid or do you want to verify that there's a real person on the other end? In the second case you'll need to do more than just run the address through Email::Valid.

    For educational purposes only, I'll point out that your regex rejects 'er_galvao_abbott@somedomain.com' and accepts 'er...galvao...abbott-_-_-_@somedomain.com'. Is that what you want?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://394126]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2021-04-18 07:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?