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    4187 Views  
Here Anand 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 Mobile Number is in correct format.
JavaScript

<script type="text/javascript">

       function isNumber(evt) {
            evt = (evt) ? evt : window.event;
            var charCode = (evt.which) ? evt.which : evt.keyCode;
            if (charCode > 31 && (charCode < 48 || charCode > 57)) {
                var errorMsg = document.getElementById("errorMsg");
                errorMsg.style.display = "block";
                document.getElementById("errorMsg").innerHTML = "  Please enter only Numbers.  ";
                return false;
            }
           
            return true;
        }

        function ValidateNo() {
            var phoneNo = document.getElementById('txtPhoneNo');
            var errorMsg = document.getElementById("errorMsg");
            var successMsg = document.getElementById("successMsg");

            if (phoneNo.value == "" || phoneNo.value == null) {
                errorMsg.style.display = "block";
                successMsg.style.display = "none";
                document.getElementById("errorMsg").innerHTML = "  Please enter your Mobile No.  ";
                return false;
            }
            if (phoneNo.value.length < 10 || phoneNo.value.length > 10) {
                errorMsg.style.display = "block";
                successMsg.style.display = "none";
                document.getElementById("errorMsg").innerHTML = "  Mobile No. is not valid, Please Enter 10 Digit Mobile No. ";
                return false;
            }

            successMsg.style.display = "block";
            document.getElementById("successMsg").innerHTML = " Success ";
            errorMsg.style.display = "none";
            return true;
            }
    </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 Phone No:</span> <span>
                <input id="txtPhoneNo" type="text" onkeypress="return isNumber(event)" />
            </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="ValidateNo();">
    </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;
    }

Demo
Enter the Mobile No. :


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


AnonymousUser
Apr 13 2016 2:53AM
what if we want to add country code or sign?

 
Search
Recent Posts
Create Amazon ElasticCache Using Memcached in CSharp
Oct 29 2018 12:09PM Posted By Amose
Get Google Map Lat Lng (Geo Point) By Pincode in C#
Oct 28 2018 12:09PM Posted By Pranav
Google URL Shortener in C#
Oct 20 2018 12:09PM Posted By Sanjay
Bind Gridview from CSV file in Asp.Net C#
Oct 5 2018 12:09PM Posted By Michael
Call WebService method from jQuery in every 1 minute
Sep 26 2018 12:09PM Posted By John
Gridview custom CSS in ASP.Net
Sep 14 2018 12:09PM Posted By Micheal Ryan
Read excel file and bind to Gridview in C#
Sep 10 2018 12:09PM Posted By Micheal
Tags
Follow us on Facebook
Follow us on Google +
Recent post in your Email inbox.
Enter your email address: