Hello JS experts -
I am trying to validate what has been entered into text boxes.... to be certain the user entered all numeric characters.
My Problem:
When I enter non-numeric characters, the isNum function is not detecting this (don't get the alert message in the ValidateInput function). Do I have an error in my code?
Thanks, John
Here is my code:
<SCRIPT language="JavaScript">
<!--
function ValidateInput()
{
if (!isNum(frmUser.Dept.value))
{
alert ("Please enter your Department number - all digits"
frmUser.Dept.focus()
return false
}
if (!isNum(frmUser.PhoneW.value))
{
alert ("Please enter your work phone number"
frmUser.PhoneW.focus()
return false
}
return true
}
// Is the entered value a Number ?
function isNum(entry)
{
alert ("In isNum...value of number box is "+ entry)
if (entry == ""
{
return false
}
for (i=0; i<entry.length; i++)
{
if (entry.charat(i) < "0" )
{
return false
}
if (entry.charat(i) > "9" )
{
return false
}
}
return true
}
-->
</SCRIPT>
I am trying to validate what has been entered into text boxes.... to be certain the user entered all numeric characters.
My Problem:
When I enter non-numeric characters, the isNum function is not detecting this (don't get the alert message in the ValidateInput function). Do I have an error in my code?
Thanks, John
Here is my code:
<SCRIPT language="JavaScript">
<!--
function ValidateInput()
{
if (!isNum(frmUser.Dept.value))
{
alert ("Please enter your Department number - all digits"
frmUser.Dept.focus()
return false
}
if (!isNum(frmUser.PhoneW.value))
{
alert ("Please enter your work phone number"
frmUser.PhoneW.focus()
return false
}
return true
}
// Is the entered value a Number ?
function isNum(entry)
{
alert ("In isNum...value of number box is "+ entry)
if (entry == ""
{
return false
}
for (i=0; i<entry.length; i++)
{
if (entry.charat(i) < "0" )
{
return false
}
if (entry.charat(i) > "9" )
{
return false
}
}
return true
}
-->
</SCRIPT>