tags:

views:

55

answers:

2

Hi boys:

I am trying to validate a TextEdit in order to contains a truly email address. I have a regular expression to do that, but it validates more than one address, and I just want to validate only one address, no more.

Here you are the expression I have:

/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/

It validates something like this:

[email protected], [email protected]

I need take the second email address out of the TextEdit.

So, How can I do that??

Note: I am sorry about my English.

A: 

Try this

/^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/
streetparade
Joe Lencioni
Hmm.. ok but it would be much more longer than the above.
streetparade
Oh yes. Very much longer. http://www.ex-parrot.com/pdw/Mail-RFC822-Address.html ...that's why you don't ‘validate’ e-mail addresses with regex.
bobince
A: 

Here is a great tutorial on Email Regex - including how to find emails in text.

http://www.regular-expressions.info/email.html

It is important to understand how Regex works and not just copy and paste.

Todd Moses