文本框必须只允许输入0到9之间的数字,字段的最大长度为5,文本框必须只接受99.99以上的值。
答案 0 :(得分:1)
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();
}
答案 1 :(得分:0)
这使代码工作:
<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>