Well, duh! That's by far much simpler. Thanks for sharing.
Bill
--- In MS_Access_Professionals@yahoogroups.com, <sw@...> wrote:
>
> What if you try LIKE operator ?
>
>
> function IsAlpha(byval stString as string)as boolean
> IsAlpha =not( stString Like "*[!a-z,A-Z,0-9]*")
> end function
>
> ... not tested, bud should work .-)
>
> or RegExp object (is a bit complicated)
>
> -jma-
>
> ----- Original Message -----
> From: "Bill Mosca" <wrmosca@...>
> To: <MS_Access_Professionals@yahoogroups.com>
> Sent: Wednesday, October 03, 2012 4:04 PM
> Subject: [MS_AccessPros] Re: Check For Non-Alphanumeric Values In String
>
>
> > Abraham
> >
> > As you see, yours is case sensitive. Mine includes both upper and lower case. If you need only upper and numeric then keep yours
> > as is.
> >
> > I found a typo in my first line. And I added some code to exit the function if the argument passed was null as it might be if
> > called in a query.
> >
> >
> > Public Function AlphaNumericOnly(varIn As Variant) As Boolean
> > Dim x As Integer
> > Dim varCharacter As Variant
> > Dim bolANOnly As Boolean
> >
> > 'Initialize flag to True.
> > bolANOnly = True
> >
> > If isnull(varIn) Then Exit Function
> >
> > 'Loop through entire varIng.
> > For x = 1 To Len(varIn)
> > 'Get a character in the varIng.
> > varCharacter = Mid(varIn, 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
> >
> >
> > --- In MS_Access_Professionals@yahoogroups.com, "Abo" <abraham@> wrote:
> >>
> >> Hi again Bill,
> >> Your code worked very well.
> >> I simplified it as follows:
> >>
> >> Public Function FAlphaNumericOnly2(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 varCharacter
> >> Case "A" To "Z", 0 To 9 'Alpha numeric characters.
> >> bolANOnly = True
> >> Case Else
> >> bolANOnly = False
> >> Exit For
> >> End Select
> >> Next
> >>
> >> FAlphaNumericOnly2 = bolANOnly
> >>
> >> End Function
> >>
> >> Specifically, the code checks the each character directly without first getting its character code.
> >> It seems to be case-insensitive.
> >>
> >> Abraham
> >>
> >> --- In MS_Access_Professionals@yahoogroups.com, "Bill Mosca" <wrmosca@> wrote:
> >> >
> >> > 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
> >> > >
> >> >
> >>
> >
> >
> >
> >
> > ------------------------------------
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
>
Rabu, 03 Oktober 2012
[MS_AccessPros] Re: Check For Non-Alphanumeric Values In String
__._,_.___
.
__,_._,___
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar