How To Find Email In String Example Using JavaScript?

Oct 01, 2021 . Admin



Hello Friends,

Now let's see example of how to find email in string example. We will use how to find email in string in javascript. Here you will learn how to use javascript find email in string. This is a short guide on find email in string. Let's get started with how to find email in string in javascript.

Here i will give you many example how you can find email in string javascript.

Example : 1
<!DOCTYPE html>
<html>
    <head>
        <title>How To Find Email In String Example Using JavaScript? - MyWebtuts.com </title>
    </head>
    <body>
    <script type='text/javascript'>
        function extractEmails ( text ){
            return text.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)/gi);
        }

        alert(extractEmails('Hi, contact on mywebtuts@gmail.com'))
        console.log(extractEmails('Hi, contact on mywebtuts@gmail.com')); 
    </script>
    </body>
</html>
Output :
mywebtuts@gmail.com
Example : 2
<!DOCTYPE html>
<html>
    <head>
        <title>How To Find Email In String Example Using JavaScript? - MyWebtuts.com </title>
    </head>
    <body>
        <p id="emails"></p>
    <script type='text/javascript'>
        var text = 'mywebtuts@mail.com, "MyWebtuts" <aatmaninfotech@gmail.com>,"aatman infotech" <nicesnippets@gmal.com>, "Nicesnippets"';  
        function extractEmails (text)
        {
            return text.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi);
        }

        console.log(extractEmails(text).join('\n'));
    </script>
    </body>
</html>
Output :
mywebtuts@mail.com
aatmaninfotech@gmail.com
nicesnippets@gmal.com

It will help you...

#Javascript