Reputation: 1810
A text box must allow to enter only numbers from 0 to 9 and the maximum length of the field is 5 and the text box must accept values upto 99.99 only.
Upvotes: 0
Views: 1364
Reputation: 1810
This got the code to work:
<HTML>
<HEAD>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<SCRIPT language=Javascript>
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode != 46 && charCode > 31
&& (charCode < 48 || charCode > 57))
return false;
return true;
}
$(document).ready(function ()
{
$('#Percentage1').keyup(function (event)
{
var currentValue = $(this).val();
var length = currentValue.length;
if (length == 2)
{
$(this).val(currentValue + ".");
}
else if (length == 3)
{
$(this).val(currentValue + "");
}
});
});
</SCRIPT>
</HEAD>
<BODY>
<input class="user-reg-input fl" type="text" name="Percentage[]" id="Percentage1" value="" onpaste="return false"
onkeypress="return isNumberKey(event)" maxlength="5" />
</BODY>
</HTML>
Upvotes: 0
Reputation: 1575
HTML INPUT TAG
<input id="input" onblur="validate(this)"/>
JAVASCRIPT
function validate(inputField)
{
if(inputField.value.length > 5)
alert("Field should be less than 5 in length");
else if(parseFloat(inputField.value) > 99.99)
alert("value should be less than 99.99");
else
this.form.submit();
}
Upvotes: 1