By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,041 Members | 1,858 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,041 IT Pros & Developers. It's quick & easy.

validation for alphanumeric

P: 23
Hi


How to give alphanumeric validation for textbox in VBA for ms access

already the textboxvalue is filled with "6hy754"
textbox="6hy754"
I have to check whether the value is alphanumeric or not
Jul 31 '08 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 634
Hi


How to give alphanumeric validation for textbox in VBA for ms access

already the textboxvalue is filled with "6hy754"
textbox="6hy754"
I have to check whether the value is alphanumeric or not
Hi

If you want to confirm that both letters and numbers are present then perhaps this function will do
Expand|Select|Wrap|Line Numbers
  1. Function IsAlphaNumeric(ByVal ThisString As String) As Boolean
  2.     Dim i As Integer
  3.     Dim Alpha As Boolean
  4.     Dim Numeric As Boolean
  5.  
  6.     Alpha = False
  7.     Numeric = False
  8.     For i = 1 To Len(ThisString)
  9.         If IsNumeric(Mid(ThisString, i, 1)) Then
  10.             Numeric = True
  11.         Else
  12.             Alpha = True
  13.         End If
  14.     Next i
  15.  
  16.     IsAlphaNumeric = Alpha And Numeric
  17. End Function
??

HTH

MTB
Jul 31 '08 #2

missinglinq
Expert 2.5K+
P: 3,532
The problem with that is that if the OP wants at least one characters that is 0-9 and at least one that is a-z, the code can fail.

98.6, 19+87, 12@3, #123, etc will all return true, because !@#$%^&*()_+ and so forth are all non-numeric, alpha characters. To assure only 0-9 and a-z characters, and at least one of each, we need to modify Mike's code a little bit. I think this does it:
Expand|Select|Wrap|Line Numbers
  1. Function IsAlphaNumeric(ByVal ThisString As String) As Boolean
  2.     Dim i As Integer
  3.     Dim Alpha As Boolean
  4.     Dim Numeric As Boolean
  5.  
  6.     Alpha = False
  7.     Numeric = False
  8.     For i = 1 To Len(ThisString)
  9.         If IsNumeric(Mid(ThisString, i, 1)) Then
  10.             Numeric = True
  11.         End If
  12.         If (Mid(ThisString, i, 1)) Like "[a-z]" Then
  13.            Alpha = True
  14.         End If
  15.     Next i
  16.  
  17.     IsAlphaNumeric = Alpha And Numeric
  18. End Function
Welcome to Bytes!

Linq ;0)>
Jul 31 '08 #3

NeoPa
Expert Mod 15k+
P: 31,494
I think it would be better if the OP specified more clearly exactly what they are after here. The question is not very clear and can be interpreted in a number of ways.
Aug 5 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.