devxlogo

International Test for Illegal Characters

International Test for Illegal Characters

Windows has the solution: the IsCharAlphaNumeric function, defined in User32.dll. This function uses the currently defined locale when performing comparisons, thereby allowing full use of accented characters. This sample demonstrates how you might use this function:

Public Declare Function IsCharAlphaNumeric Lib _	"user32" Alias "IsCharAlphaNumericA" ( _	ByVal cChar As Byte) As LongPublic Function IsAlphaNum(ByVal sInput As String) _	As Boolean	Dim fCheck As Boolean	Dim i As Integer	 	' Assume non-alphanumeric	fCheck = False		' If we don't have any input, drop out	If Len(sInput) Then		i = 0		Do			i = i + 1			fCheck = _				CBool(IsCharAlphaNumeric( _				Asc(Mid$(sInput, i, 1))))		Loop While fCheck And (i 

You may pass any single or multiple character string to the function IsAlphaNum. The return value will be True if all characters are alphanumeric and False otherwise.

Windows also has several other useful functions for working with characters in the current locale. Note, however, that all functions require a byte to be passed, which you can achieve by passing the Asc() value of a given character (see previous example):

' Check if a given character is alphabeticPublic Declare Function IsCharAlpha Lib "user32" _	Alias "IsCharAlphaA" (ByVal cChar As Byte) _	As Long' Check if a given character is lowercasePublic Declare Function IsCharLower Lib "user32" _	Alias "IsCharLowerA" (ByVal cChar As Byte) _	As Long' Check if a given character is uppercasePublic Declare Function IsCharUpper Lib "user32" _	Alias "IsCharUpperA" (ByVal cChar As Byte) _	As Long

devx-admin

Share the Post: