Selasa, 02 Oktober 2012

[MS_AccessPros] Re: Check For Non-Alphanumeric Values In String

 

Abraham

I broke this down into little steps so you could see what I'm doing. This loops through the string argument and looks for alpha numeric characters. If any special characters are found it immediately returns false. Otherwise, it returns true.

Public Function AlphaNumericOnly(strIn As String) As Boolean
Dim x As Integer
Dim varCharacter As Variant
Dim bolANOnly As Boolean

'Initialize flag to True.
bolANOnly = True

'Loop through entire string.
For x = 1 To Len(strIn)
'Get a character in the string.
varCharacter = Mid(strIn, x, 1)
Select Case Asc(varCharacter)
'Alpha numeric characters.
Case 48 To 57, 65 To 90, 97 To 122
bolANOnly = True
Case Else
bolANOnly = False
Exit For
End Select
Next

AlphaNumericOnly = bolANOnly

End Function

Regards,
Bill Mosca, Founder - MS_Access_Professionals
http://www.thatlldoit.com
Microsoft Office Access MVP
https://mvp.support.microsoft.com/profile=C4D9F5E7-BB03-4291-B816-64270730881E
My nothing-to-do-with-Access blog
http://wrmosca.wordpress.com

--- In MS_Access_Professionals@yahoogroups.com, "Abo" <abraham@...> wrote:
>
> Hello,
>
> I would like to check/ensure that a string contains only numbers and/or alphabet characters. No special characters.
>
> Is there a simple way to do this? Something similar to IsNumeric?
>
> Abraham
>

__._,_.___
Recent Activity:
.

__,_._,___

Tidak ada komentar:

Posting Komentar