Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: VB4/32, VB5, VB6
Expertise: Intermediate
Sep 10, 2003



Building the Right Environment to Support AI, Machine Learning and Deep Learning

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 Long

Public 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
			i = i + 1
			fCheck = _
				CBool(IsCharAlphaNumeric( _
				Asc(Mid$(sInput, i, 1))))
		Loop While fCheck And (i < Len(sInput))
	End If
	IsAlphaNum = fCheck
End Function
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 alphabetic
Public Declare Function IsCharAlpha Lib "user32" _
	Alias "IsCharAlphaA" (ByVal cChar As Byte) _
	As Long

' Check if a given character is lowercase
Public Declare Function IsCharLower Lib "user32" _
	Alias "IsCharLowerA" (ByVal cChar As Byte) _
	As Long

' Check if a given character is uppercase
Public Declare Function IsCharUpper Lib "user32" _
	Alias "IsCharUpperA" (ByVal cChar As Byte) _
	As Long
John Cullen
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date