First thing, whenever you pull a field value in JavaScript it always returns a string.
This, frmCusInfo.txtAge.value, will always return a string.
Try using Regular Expressions or look below at my example.
Let's look at my example below where I only allow dollar amounts and formatting. You can modify to fit your needs.
<!-- Function Description: Validates Non Currencys fields. -->
function validateDollar( fld )
{
var temp_value = fld.value;
if (tempvalue == "")
{
fld.value = "$0.00";
return;
}
var Chars = "0123456789.,$";
for (var i = 0; i < tempvalue.length; i++)
{
if (Chars.indexOf(temp_value.charAt(i)) == -1)
{
alert("Invalid Character(s)\n\nOnly numbers (0-9), a dollar sign, a comma, and a period are allowed in this field.");
fld.focus();
fld.select();
return;
}
}
}
Enter your message below
Sign in or Join us (it's free).