|
-
June 22nd, 2006, 04:01 AM
#1
Restricting Key Stokes in text box
Hello
I have an web application (asp.net + C#)
I have an textbox that is always filled with numeric value.
i want to restrict other all the key press except the numeric key & - .
as for the phone the hyphen is required.
How to implement it?
I tried but no success.
Any Idea?
-
June 22nd, 2006, 04:16 AM
#2
Re: Restricting Key Stokes in text box
As pressing a key in a web-browser is a client side event, so you will have to use Client Side Javascript to do that.
Here is a script that will allow only numbers in a textbox
Code:
<SCRIPT language=javascript>
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 45 && (charCode < 48 || charCode > 57))
return false;
return true;
}
</SCRIPT>
Remember in your HTML part of the TextBox you will have to write this onkeypress="return isNumberKey(event)"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|