Click to See Complete Forum and Search --> : checking a variable is numeric


OhLordy
04-09-2003, 02:58 AM
How can I check if a supplied variable is numeric?
Thank you in advance.
Rob

SniperX
04-09-2003, 03:36 AM
Hi you might wanna try this

<script>
<!--
function checkNumberic() {
var num = document.formname.inputname.value;

if (isNaN(num)) { alert("WARNING: Input must be numeric!!"); return false; }
return true;
}
-->
</script>

isNaN() returns 1 if the input consisted of letters
and returns 0 if the input was numerical.

Hope I helped
MW:D

SniperX
04-09-2003, 07:26 AM
Thanks for pointing out my mistake,
It is always good to know where you went wrong.

But is it neccessary to use the Number() function - because my way does work, or is number coding standard?

SniperX
04-09-2003, 07:41 AM
Thanks for clearing that up.

Kind Regards
MW