Share Blog

Friday, August 01, 2014

How to Check Upper Case letter And Only Numeric And Alphabet Input In TextBox Validation Using JavaScript

TextBox with Only Alphabet Characters allowed.

    <script type="text/javascript">
        function valid(e) {
            var num;
            var chars;
            var check;
            if (window.event) {
                num = e.keyCode;
            }
            else if (e.which) {
                num = e.which;
            }
            chars = String.fromCharCode(num);
            check = /\d/;
            return !check.test(chars);
        }

    </script>

TextBox with Only Numeric Characters allowed.

<script language="Javascript" type="text/javascript">
      <!--
        function isNumeric(keyCode) {
            if (keyCode == 16)
                isShift = true;

            return ((keyCode >= 48 && keyCode <= 57 || keyCode == 8 ||
            (keyCode >= 96 && keyCode <= 105)) && isShift == false);
        }
         //-->
    </script>

TextBox Upper Case Letter.

<script type="text/javascript">
        function toUpper(txt) {
            document.getElementById(txt).value = document.getElementById(txt).value.toUpperCase();
            return true;
        }
    </script>

To call the textbox on onkeydown,onkeyup,onkeypress event, see below

<asp:TextBox ID="Txtcity1" runat="server" onkeyup="return toUpper(this.id)" onkeypress="return valid(event)"></asp:TextBox>

 <asp:TextBox ID="Txtpincode1" runat="server" onkeydown = "return isNumeric(event.keyCode)"></asp:TextBox>

No comments:

Post a Comment