Tuesday 25 October 2016

HOW TO VALIDATE INPUT FIELD NUMERIC WITH FIXED NUMBER.

HOW TO VALIDATE INPUT FIELD NUMERIC WITH FIXED NUMBER OF DIGIT


Validation for Number(CONTACT NUMBER (10 Digit max )).

--------------------------------------------------------------------------------------------------------------------------
<script language="javascript" type="text/javascript">

    function fixedlength(textboxID, keyEvent, maxlength) {
        //validation for digits upto 'maxlength' defined by caller function
        if (textboxID.value.length > maxlength) {
            textboxID.value = textboxID.value.substr(0, maxlength);
        }
        else if (textboxID.value.length < maxlength || textboxID.value.length == maxlength) {
            textboxID.value = textboxID.value.replace(/[^\d]+/g, '');
            return true;
        }
        else
            return false;
    }

    function CheckMax(controlname) {
        var num = document.getElementById('<%=txtAmount.ClientID %>').value;
        if (num > 100 || num <= 0) {
            alert('Please Enter Value between 1 to 100');
            document.getElementById('<%=txtAmount.ClientID %>').value = '';
               document.getElementById('<%=txtAmount.ClientID %>').focus();
            return false;
        }
     return true;
 }
</script>
--------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------

<form id="form1" runat="server" action="ValidateFormWebUI.aspx" autocomplete="off">
        
            
            <div class="submain">
                <table class="tblform">
                    <tbody>
                          <tr>
                            <td class="textfield" title="Enter Name">Name</td>
                            <td class="textfield">
                                <input id="txtName" name="NAME" class="InputField" maxlength="150" type="text" value="" /></td>
                        </tr>
                        <tr>
                            <td class="textfield" title="Enter Name">Contact</td>
                            <td class="textfield"><asp:textbox class="InputField" id="txtContactNo" runat="server" maxlength="10" onblur="return fixedlength(this, event, 10);" onkeypress="return fixedlength(this, event, 10);" onkeyup="return fixedlength(this, event, 10);"></asp:textbox></td>
                        </tr>
                         <tr>
                            <td class="textfield" title="Enter Name">Amount (0-100)</td>
                            <td class="textfield"><asp:textbox class="InputField" id="txtAmount" runat="server" maxlength="3"></asp:textbox></td>
                        </tr>
                    </tbody>
                </table>
            </div>
       
    </form>

Factorial of a Number

Recently Viewed