Click here to Skip to main content
15,908,455 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
how to validate alpha numeric values in textbox using jquery?
Posted

Hi,

Try like this:

XML
<script type="text/javascript">
        $(function() {
            $('input.alpha[$id=tb1]').keyup(function() {
                if (this.value.match(/[^a-zA-Z0-9 ]/g)) {
                    this.value = this.value.replace(/[^a-zA-Z0-9 ]/g, '');
                }
            });
        });
    </script>


or

XML
<script type="text/javascript">
function alphanumeric(alphane)
{
        var numaric = alphane;
        for(var j=0; j<numaric.length; j++)
                {
                  var alphaa = numaric.charAt(j);
                  var hh = alphaa.charCodeAt(0);
                  if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
                  {
                  }
                else {
                         alert("Your Alpha Numeric Test Failed");
                         return false;
                  }
                }
 alert("Your Alpha Numeric Test Passed");
 return true;
}
</script>


Refer the following link:
Click here for more details

Thanks
 
Share this answer
 
v2
Comments
Hari Krishna Prasad Inakoti 22-Feb-13 7:47am    
sorry @sisirp88,
It is not working
[no name] 22-Feb-13 7:57am    
I have tried its working fine for me...
Can you specify your inputs that you are using for the textbox?
Try below..
JQuery code below..
JavaScript
<script language="javascript" type="text/javascript">
function alphanumericsonly(ob) 
    {
        var invalidChars = /([^a-z0-9])/gi
        if(invalidChars.test(ob.value)) 
        {
            ob.value = ob.value.replace(invalidChars,"");
        }
    }

$('.mobile').keyup(function()
            {
                alphanumericsonly(this);

            });

Text box below..
XML
<asp:TextBox ID="TextBox1" class="mobile" runat="server"></asp:TextBox>

Above code will restricts other characters except alphanumerics on keyup event...
Hope this works fine..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900