PDA

View Full Version : validation problem



vinod singh
06-16-2009, 02:58 AM
how to restrict user not to enter any string type (by showing warning message)value in textbox which accepts only numeric value

forum_amnesiac
06-16-2009, 07:08 AM
Here are 2 simple functions to validate the entry of a whole number or a numeric value that includes decimals.


<html>
<head>
<script>
function wholenum(fieldwval){
wholeval=fieldwval.value;
if (wholeval != parseInt(wholeval)){
alert(wholeval + ' is not a whole number');
testform.whole.name.select();
testform.whole.name.focus();
}
}

function numfield(fieldval){
numval=fieldval.value;
if (numval != parseFloat(numval)){
alert(numval + ' is not a number');
testform.number.name.select();
testform.number.name.focus();
}
}

</script>
</head>
<body>
<form name="testform">
<input type="text" name="whole" onBlur="wholenum(this)">Enter a whole number
<br>
<input type="text" name="number" onBlur="numfield(this)">Enter any number (incl. decimals)
</html>