Thursday 6 June 2013

JAVASCRIPT : Validate a decimal number in a textbox on a data entry form and accept only one decimal point

function isNumberKeyAndDot(event, value) {
    var charCode = (event.which) ? event.which : event.keyCode
    var intcount = 0;
    var stramount = value;
    for (var i = 0; i < stramount.length; i++) {
        if (stramount.charAt(i) == '.' && charCode==46) {
            return false;
        }
    }   
    if ((charCode > 31 && (charCode < 48 || charCode > 57)) && charCode != 46)
        return false;
    return true;


Source Code:

<asp:TextBox ID="txtdiscvalue" runat="server"  onkeypress="return isNumberKeyAndDot(event,value)"></asp:TextBox>

No comments:

Post a Comment