VB icon

isAlphaNumeric

Email
Submitted on: 1/5/2015 11:51:00 AM
By: Ramon Morales (from psc cd)  
Level: Beginner
User Rating: By 5 Users
Compatibility: ASP (Active Server Pages)
Views: 1869
 
     Function to determine if the passed parameter is AlphaNumeric (the string contains only A-Z, a-z or 1-0). Heavily commented. Bug Fixed.
 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
' for :isAlphaNumeric
'**************************************
Public Domain
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: isAlphaNumeric
' Description:Function to determine if the passed parameter is AlphaNumeric (the string contains only A-Z, a-z or 1-0). Heavily commented. Bug Fixed.
' By: Ramon Morales (from psc cd)
'
' Inputs:The string to be evaluated.
'
' Returns:Returns True is the string is AlphaNumeric and False if it is not.
'
' Assumes:See comments.
'
' Side Effects:None.
'**************************************

	Function IsAlphaNumeric(sText)
	'***************************************************************************
	'Checks to see if sText is made up of only Alphabetic characters (A-Z) or 
	'Numbers. If it has any other characters, IsAlphaNumeric will be False.
	'***************************************************************************
		Dim nLen, nLoop, sTemp,	sSingleCharacter
		Dim bAlphaStatus
		
	'***************************************************************************
	'Default value
	'***************************************************************************
		bAlphaStatus = True
		
	'***************************************************************************
	'Gets length of the sText variable.
	'***************************************************************************
		sTemp = Trim(sText)
		nLen = Len(sTemp)
	'***************************************************************************
	'If the length of sText is 0, then it is not AlphaNumeric and 
	'IsAlphaNumeric = False.
	'***************************************************************************
		If nLen = 0 then
			bAlphaStatus = False
		End If	'If nLen = 0 then
		If nLen > 0 then
	'***************************************************************************
	'Convert sText to uppercase to make comparisons easier.
	'***************************************************************************
			sTemp = Ucase(sTemp)
	'***************************************************************************
	'Will loop nLen times. It will check each of the characters of sText against
	'the comparison string (which is A-Z and 1-0). It will check it one 
	'character at a time (beginning with the farthest left character).If the 
	'Instr command shows a 0 (meaning it could not find a match), that character 
	'was not AlphaNumeric.
	'***************************************************************************
			For nLoop =1 to nLen
				sSingleCharacter = Mid(sTemp,nLoop,1)
				If Instr("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", sSingleCharacter)= 0 then
					bAlphaStatus = False
					Exit For
				End If
			Next
	'***************************************************************************
	'If sText managed to get through the above filters without changing 
	'IsAlphaNumeric to False, then IsAlphaNumeric is True.
	'***************************************************************************
			If bAlphaStatus <> False then
				bAlphaStatus = True
			End If
		End If	'If nLen > 0 then
		
		IsAlphaNumeric = bAlphaStatus
		
	End Function


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.