Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Evaluate string for numbers and spaces OnBlur 1

Status
Not open for further replies.

BHaines

Programmer
May 29, 2003
100
US
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 <> &quot;&quot; then
if Not IsNumeric(Trim(StartAccount.value)) then
StartAccount.Style.Color = &quot;#FF0000&quot;
MsgBox &quot;This value must be a numbers only.&quot;, 64, &quot;Invalid Account Number&quot;
StartAccount.Focus
else
StartAccount.Style.Color = &quot;#000000&quot;
end if
else
StartAccount.Style.Color = &quot;#000000&quot;
end if
end function
 
Code:
function AccountCheck
Dim StartAccount, myArray, i
set StartAccount = window.event.srcElement
if StartAccount.value <> &quot;&quot; then
  myArray = Split(Trim(StartAccount.value))
  For i = 0 To Ubound(myArray)
    if Not IsNumeric(myArray(i)) then
      StartAccount.Style.Color = &quot;#FF0000&quot;
      MsgBox &quot;This value must be a numbers only.&quot;, 64, &quot;Invalid Account Number&quot;
      StartAccount.Focus
      Exit Function
    End If
  Next
End If
StartAccount.Style.Color = &quot;#000000&quot;
end function

Hope This Help
PH.
 
forgot I wrote this faq329-2056 but it should help

____________________________________________________
get the best answer to your questions by asking the best questions &quot;General FAQ&quot; faq333-2924
onpnt2.gif
 
PHV you rock my world! It's perfect! Thank you so much!!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top