asudhaa
asked on
Paste only Numeric value in textbox
I have created dynamic text boxes .I would like to enter only numeric values.It works fine when key is pressd.But when i copy and paste i am able to paste non integer values.
how can I paste only numberic values and not non integer values?
tb.Attributes.Add("onkeypr ess", "return isNumberKey(event);");
the javascript code is
<script type="text/javascript">
function isNumberKey(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
{
alert("Please enter a Numeric value");
return false;
}
return true;
}
</script>
how can I paste only numberic values and not non integer values?
tb.Attributes.Add("onkeypr
the javascript code is
<script type="text/javascript">
function isNumberKey(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
{
alert("Please enter a Numeric value");
return false;
}
return true;
}
</script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
handle the TextChanged event to validate your complete field as shown in http://emoreau.com/Entries/Articles/2003/03/Creating-your-own-Windows-Custom-Control.aspx
if(NaN(value)) ... tells whether the value is a number or not
function isNumberKey(val)
{
if(isNaN(val)){
val = val.substring(0, val.length-1);
document.form1.txtAge.valu
alert("Please enter a Numeric value");
return false;
}
return true;
}