News
IBM to offer mobile security as a service IBM will start delivering mobile security-as-a-service (MaaS) through its own cloud infrastructure in India, a move that is expected to better address in-country data requirements... IBM Spectrum Computing: IBM has enlarged its portfolio of software-defined infrastructure solutions with cognitive features for workload management.  * LiFi internet technology has been introduced, the new type of wireless internet connection that gives 100 times faster than traditional WiFi -- Invented by Professor Harald Haas from the University of Edinburgh. * Sci. Rachid Yazami has developed a smart chip that charges smartphones in less than 10 minutes. BenQ has launched BlueCore projector - Consumer electronics major BenQ has launched its first BlueCore laser light source projector. For those unaware, devices with BlueCore laser technology have a high contrast output of 80000:1 with an extended lamp life and efficiency. ***
  Dec 14 2014 8:31AM     Anand
  1 Comments    1485 Views  
Here John discussed about Email Validation in Javascript.
Java Script is dynamic and most commonly used in all programming languages.
This validation is verifying that the supplied email address is in correct format.
JavaScript

<script type="text/javascript">

        function validateEmail() {

            var email = document.getElementById('txtEmail');
            var mailFormat = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
            var errorMsg = document.getElementById("errorMsg");
            var successMsg = document.getElementById("successMsg");

            if (email.value == "") {
                errorMsg.style.display = "block";
                document.getElementById("errorMsg").innerHTML = "  Please enter your Email Id  ";
            }
            else if (!mailFormat.test(email.value)) {
                errorMsg.style.display = "block";
                document.getElementById("errorMsg").innerHTML = "  Email Address is not valid, Please provide a valid Email ";
                email.focus;
                return false;
            }
            else {
                successMsg.style.display = "block";
                document.getElementById("successMsg").innerHTML = " Success ";
                errorMsg.style.display = "none";
            }
            
        }
    </script>

Html

<body>
    <form id="form1" runat="server">
    <div class="algContent">
        Email Validation In JavaScript
    </div>
    <br >
    <br >
    <br >
    <div class="algContent">
        <div style="float:left;">
            <span>Enter the Email:</span> <span>
                <input id="txtEmail" type="text" />
            </span>
        </div>
        <div style="float:left;">
        <span style="float:left;" id="errorMsg" class="dsNone error"></span><span style="float:left;" id="successMsg" class="dsNone success">
        </span>
        </div>
        <br ><br >
        <input type="button" value="Submit" onclick="validateEmail();">
    </div>
    </form>
</body>

CSS

<style type="text/css">
    .error
    {
        color: white;
        background-color: rgb(247, 23, 23);
        margin-left: 12px;
        border-radius: 3px;
    }

    .dsNone
    {
        display:none;
    }

    .success
    {
        color: white;
        background-color: green;
        margin-left: 12px;
        border-radius: 3px;
    }

    .algContent
    {
        width:900px; margin:0 auto;
    }

    </style>

Demo
Enter the Email:


I hope this page will helps you to validate any kind of forms using Javascript.Thanks.
BackToTop
Comments


AnonymousUser
Mar 21 2016 10:54AM
why error msg is blim and go

 
Search
Recent Posts
Create Amazon ElasticCache Using Memcached in CSharp
Nov 21 2017 12:09PM Posted By Amose
Get Google Map Lat Lng (Geo Point) By Pincode in C#
Nov 8 2017 10:26AM Posted By Pranav
Google URL Shortener in C#
Oct 26 2017 10:43AM Posted By Sanjay
Bind Gridview from CSV file in Asp.Net C#
Jun 18 2017 11:38PM Posted By Michael
Call WebService method from jQuery in every 1 minute
Feb 27 2017 11:51AM Posted By John
Gridview custom CSS in ASP.Net
Feb 25 2017 10:59AM Posted By Micheal Ryan
Read excel file and bind to Gridview in C#
Feb 25 2017 10:20AM Posted By Micheal
Tags
Follow us on Facebook
Follow us on Google +
Recent post in your Email inbox.
Enter your email address: