0

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) [email protected] (Blig fun), [email protected] (LOl)

I need the output like 

[email protected]
[email protected] 

1 Answer 1

3

Try -

var tbstring = '(a) [email protected] (Blig fun), [email protected] (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.

Sign up to request clarification or add additional context in comments.

2 Comments

@Mr.Black then you should flag this solution as your answer! ;)
"New-fangled"? .museum has been around for about a decade!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.