Click here to Skip to main content
15,898,588 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am using textbox where user enter amount..But i want to the user to restrict from entering alphabets in web application?

plz help

regards
manohar
Posted
Comments
BillWoodruff 27-Jan-12 9:35am    
Exactly what does "web application" mean here ? SilverLight ? One of the five possible choices for Visual Studio ASP.NET "Web Application" ? ... JavaScript within ASP.NET ? ... what ?

Try this,

js function :

C#
function isNumberKey(evt, ctrlName) {
    var str = ctrlName.value;
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 && charCode != 46) || charCode > 57) {
        return false;
    }
    else if (charCode == 46 && (str.indexOf(".") != -1)) {
        return false;
    }
    else {
        return true;
    }
}


Calling way:

XML
<asp:TextBox ID="txt_rate" runat="server" Width="103px" onkeypress="return isNumberKey(event,this)" ></asp:TextBox>
 
Share this answer
 
Comments
thatraja 28-Jan-12 14:19pm    
Right, 5!

BTW you know General Indian Topics? Its a forum(to discuss anything) for Indian people in Codeproject(Around 30-40 members there)
Supriya Srivastav 30-Jan-12 0:40am    
Thanks thatraja.....
Ya, I know about that but never participated yet.
vinodkumarnie 31-Jan-13 5:58am    
nice one..
Option 1: Use AJAX controls like MaskedEdit:
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/MaskedEdit/MaskedEdit.aspx[^]

Option 2: Use Javascript, and read every Input before allowing it to appear on the control.
 
Share this answer
 
v2
Comments
thatraja 28-Jan-12 14:18pm    
Nice alternates, 5!

BTW you know General Indian Topics? Its a forum(to discuss anything) for Indian people in Codeproject(Around 30-40 members there)

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