• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 932
  • Last Modified:

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("onkeypress", "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>
0
asudhaa
Asked:
asudhaa
1 Solution
 
sarabhaiCommented:
try this...

function isNumberKey(val)
    {
    if(isNaN(val)){
    val = val.substring(0, val.length-1);
    document.form1.txtAge.value = val;
   alert("Please enter a Numeric value");
    return false;
    }
    return true;
    }
0
 
Éric MoreauSenior .Net ConsultantCommented:
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
0
 
jzkiddingCommented:
if(NaN(value)) ... tells whether the value is a number or not
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now