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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help Validating Strings & Numbers.

Status
Not open for further replies.

Robeen

Programmer
Mar 25, 2003
38
US
I'm looking for a function that will look at each character in a string and verify whether it is alpha [a-z or A-Z] or numeric [0 - 9].

Is the best way to do this in VB to test the ASCII value of each character / number that is being validated?

I'd like to know the most efficient way.

I would appreciate any help or pointers.

Thanks!

Robeen
 
for numbers there is the IsNumeric function, but i dont think there is an alpha version so checking for ascii values would probably be better!

good luck

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
 
Private Function IsAlphaNumeric(ByVal arg As String, ByVal sReason As String) As Boolean
Dim sbuffer As String
For nCharacter = 1 To Len(arg)
sbuffer = Mid$(arg1, nCharacter, 1)
If Not (LCase(sbuffer) Like "[a-z]" Or IsNumeric(sbuffer)) Then: IsAlphaNumeric = False: _
sReason = "Invalid character": Exit Function
Next nCharacter

End Function
 
Thanks jtran34!
I wrote a function that is available to every Form -
That validates for Text Only -
With a For Next Loop based on the length of the string - That checks that the ASCII value of each character is in 65-90 or 97-122 -
And returns the offending character [if any] to the calling
routine.
Kind of what you were suggesting :) ?
Robeen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top