I'm posting this here and the Javascript forum at the recommendation of someone in the ASP Forum. I have an ASP page with a form in it. In the form there is a text input box for an account number. Users can enter multiple account numbers in it and often do. The department using the app wants it to check that only numbers and spaces are in that box. I've got code to check for numbers only, and that works great, but how in the Sam Hill can I get it modified to check for spaces as well? This must occur on the OnBlur event, when the user removes focus from the input box they typed in. I know Trim will take spaces out of the left or right sides of a value, is there something that will strip them out of a whole string before I pass the value to the vbscript code below for IsNumeric validation? Or is there another way to do this?
Basically, when the user types in the CurrentAccountNo input box, they can type in as many account numbers, separated by a space, as they need to. Account numbers vary in length. When they move out of the box (OnBlur) it needs to evaluate what's in that box, and pop up and alert box if the content has anything other than numbers and spaces in it. My vbscript code below only checks to see if there is a number in the box, any spaces foil it.
function AccountCheck
Dim StartAccount
set StartAccount = window.event.srcElement
if StartAccount.value <> "" then
if Not IsNumeric(Trim(StartAccount.value)) then
StartAccount.Style.Color = "#FF0000"
MsgBox "This value must be a numbers only.", 64, "Invalid Account Number"
StartAccount.Focus
else
StartAccount.Style.Color = "#000000"
end if
else
StartAccount.Style.Color = "#000000"
end if
end function
Basically, when the user types in the CurrentAccountNo input box, they can type in as many account numbers, separated by a space, as they need to. Account numbers vary in length. When they move out of the box (OnBlur) it needs to evaluate what's in that box, and pop up and alert box if the content has anything other than numbers and spaces in it. My vbscript code below only checks to see if there is a number in the box, any spaces foil it.
function AccountCheck
Dim StartAccount
set StartAccount = window.event.srcElement
if StartAccount.value <> "" then
if Not IsNumeric(Trim(StartAccount.value)) then
StartAccount.Style.Color = "#FF0000"
MsgBox "This value must be a numbers only.", 64, "Invalid Account Number"
StartAccount.Focus
else
StartAccount.Style.Color = "#000000"
end if
else
StartAccount.Style.Color = "#000000"
end if
end function