Marks field validation
I want numeric javascript validation for marks field. Marks entered should be out of 5 means user can enter upto 5 marks not more than that. marks may be in decimal like 4.25 after decimal there should be 2 digits can any one help me..
My text box is inside the data grid so on item data bound iam doing coding like If e.Item.ItemType = ListItemType.Alt开发者_开发知识库ernatingItem Or e.Item.ItemType = ListItemType.Item Then
TxtMarks = CType(e.Item.FindControl("TxtMarks"), TextBox)
TxtMarks.Attributes.Add("onkeypress", "javascript:return validateMark()")
End If
but iam not getting proper code to validate my requirement.
TxtMarks = CType(e.Item.FindControl("TxtMarks"), TextBox)
TxtMarks.Attributes.Add("onkeypress", "return validateMark()")
End If
Try this.
You should be delete javascript: in onkeypress value
function validateMark(e) {
var value = e.target.value;
value = parseFloat(value.substring(0, 4));
if (isNaN(value)) {
return false;
}
if (value < 0 || value > 5) {
return false;
}
return true;
}
精彩评论