[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

regarding validation of email address.

Vamsi Krishna

7/28/2008 11:45:00 AM

hi all

i used the following reg. expression

/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
for validating an email address.

and its work nice. *but i need to add + in the validation as i need it

ex: user+tag@gmail.com

so in order to validate this where should i put + symbol in regular
expression so that i send emails to user+tag@gmail.com.


thanks in advance.
--
Posted via http://www.ruby-....

3 Answers

Farrel Lifson

7/28/2008 11:49:00 AM

0

2008/7/28 Vamsi Krishna <vamsikrishna.naidu@gmail.com>:
> hi all
>
> i used the following reg. expression
>
> /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
> for validating an email address.
>
> and its work nice. *but i need to add + in the validation as i need it
>
> ex: user+tag@gmail.com
>
> so in order to validate this where should i put + symbol in regular
> expression so that i send emails to user+tag@gmail.com.

Have a look at http://tfletcher.com/lib...

Regards,
Farrel

Phlip

7/28/2008 2:15:00 PM

0

Vamsi Krishna wrote:

> ex: user+tag@gmail.com
>
> so in order to validate this where should i put + symbol in regular
> expression so that i send emails to user+tag@gmail.com.

E-mail address validation is a FAQ in the Regular Expression discipline.

You can't do it. No Regexp can successfully distinguish valid from invalid
e-mail addresses, in all their permutations.

If you want to provide a simple defense against typographical errors, such as
omitting the @, you must write a Regexp that is too wide, and will permit some
ill-formed addresses to slip past.

--
Phlip

Kyle Schmitt

7/28/2008 5:12:00 PM

0

On Mon, Jul 28, 2008 at 9:19 AM, Phlip <phlip2005@gmail.com> wrote:
> E-mail address validation is a FAQ in the Regular Expression discipline.
>
> You can't do it. No Regexp can successfully distinguish valid from invalid
> e-mail addresses, in all their permutations.
>
> If you want to provide a simple defense against typographical errors, such
> as omitting the @, you must write a Regexp that is too wide, and will permit
> some ill-formed addresses to slip past.
>
> --
> Phlip
Actually I believe it _can_ be done, but it's next to useless to do so.
There's a nasty regex that claims to validate all RFC 2822 compliant
email addresses over at regular-expressions.info, and it was done so
just to show that it really is a bad idea. The regex Is really really
hideous, but the article on why not to do it is well done.
http://www.regular-expressions.info/...

For those who don't want to read the article, the last paragraph is
one that should be remembered when using regexes..

"Don't blindly copy regular expressions from online libraries or
discussion forums. Always test them on your own data and with your own
applications."




--Kyle