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    2905 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
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
Read excel file and convert to List in C#
Feb 25 2017 6:26AM Posted By Michael
Encryption and Decryption for Password in C#
Feb 17 2017 3:52AM Posted By Michael
How to create Chart in ASP.Net C#
Feb 16 2016 8:03AM Posted By Michael Ryan
Tags
Follow us on Facebook
Follow us on Google +
Recent post in your Email inbox.
Enter your email address: