简体   繁体   中英

get email ids from the given string using javascript

I have a value (a) in my textbox. I want to get the email ids only from the given string using Javascript (I don't want to use any JS Frameworks).

(a) xxx@gmail.com (Blig fun), yyy@gmail.info (LOl)

I need the output like 

xxx@gmail.com
yyy@gmail.info 

Try -

var tbstring = '(a) xxx@gmail.com (Blig fun), yyy@gmail.info (LOl)';
result = tbstring.match(/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/ig);
alert(result.join('\n'));

Demo - http://jsfiddle.net/ipr101/MM7Aa/

Email RegEx is taken from the RegEx Buddy library and comes with the following provisos -

Does not match email addresses using an IP address instead of a domain name.

Does not match email addresses on new-fangled top-level domains with more than 4 letters such as .museum. Including these increases the risk of false positives when applying the regex to random documents.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM