Home
Manage Your Code
Snippet: Limit input characters of 0-9 only using javascript (C#)
Title: Limit input characters of 0-9 only using javascript Language: C#
Description: This provides a simple way to limit characters of 0-9 only using javascript and keypress. Views: 254
Author: Thomas Jenkins Date Added: 10/20/2008
Copy Code  
1<script type="text/javascript">
2    function noAlpha(obj)
3    {
4        reg = /[^0-9]/g;
5        obj.value =  obj.value.replace(reg,"");
6    } 
7</script>
8<script runat="server">
9    protected void Page_Load(object sender, EventArgs e)
10    {
11        frmPhysicanTelephone.Attributes.Add("onKeyUp", "noAlpha(this);");
12        frmPhysicanTelephone.Attributes.Add("onKeyPress", "noAlpha(this);");
13    }
14</script>
Usage
Just as you see it. Replace frmPhysicanTelephone with the textfield name of your choice.