开发者

Regular expression to match email addresses

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 mor开发者_JAVA技巧e 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:

yulien.paz@cav.desoft.cu, wcampbell@cav.desoft.cu

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

So, How can I do that??

Note: I am sorry about my English.


Here a great library of regular expressions

http://regexlib.com/Search.aspx?k=email

And tester of regexp.

This is a sample http://regexlib.com/REDetails.aspx?regexp_id=88

^([\w-.]+)@(([([0-9]{1,3}.){3}[0-9]{1,3}])|(([\w-]+.)+)([a-zA-Z]{2,4}))$


In order to find email address inside a paragraph, none of the the above works. Instead you need to look for word boundary, ex.

\b[_\S\d-]+@[_\S\d-]+\.[\S]{2,3}\b

And then use /g if needed.


Try this

/^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜