-1

I am trying to check only alphabet in textbox(like XYZ) and any alphanumeric or special character value not entered. But my function only check numeric value and one more condition applied, if i pass alphanumeric value or special character in the textbox with alphabet or without alphabet then it will be not accept the textbox value. So please help me..

<script>
            function Enable() {
                var txt = document.getElementById("textbox");
                if (!isNaN(txt.value) || txt.value == "") {
                    alert("Blank or numeric value");
                }
                else
                    alert("Not numeric value");
            }

        </script>
        <input type="button" onclick="Enable();" value="Add" />
        <input type="text" id="textbox" />
S. S. Rawat
  • 5,943
  • 4
  • 43
  • 59
  • Sorry but question different from this.. that question only check those character according to ASCII code but code check all key available in keyboard.. @MrCode – S. S. Rawat Jun 24 '13 at 06:43

1 Answers1

2

You can try this regex to validate the input in the input box:

/^a-zA-Z$/i

You can bind the keyup event. When the event triggers, validate the value of the input box against the above mentioned regex, and replace with the desired value. Something like this:

$(this).val($(this).val().replace(/[^a-zA-Z]/g, ''));
Ali Shah Ahmed
  • 3,263
  • 3
  • 24
  • 22