Adds

Sunday, 18 January 2015

Bangladesh Mobile Number Validation Using JavaScript

C# Control
=========



<asp:TextBox ID="txtSMSNotification" class="input-semi-large" runat="server" onchange="ValidateMobNumber();"></asp:TextBox>


JavaScript Control
==============

<script type="text/javascript">

        function ValidateMobNumber() {
            var fld = document.getElementById("ContentPlaceHolder_txtSMSNotification");


            if (fld.value == "") {
                alert("You didn't enter a sms notification number.");
                fld.value = "";
                fld.focus();
                return false;
            }

            var mySplitResult = fld.value.substring(0, 2);

            if (mySplitResult != "01") {
                alert("Not in correct format");
                fld.value = "";
                fld.focus();
                return false;
            }
            if (isNaN(fld.value)) {
                alert("SMS notification number contains illegal characters.");
                fld.value = "";
                fld.focus();
                return false;
            }
            if (!(fld.value.length == 11)) {
                alert("SMS notification number is the wrong length. \nPlease enter 11 digit mobile no.");
                fld.value = "";
                fld.focus();
                return false;
            }

        }
           
    </script>