Answer» So I have an MS Access db application that I'm working on. The part that i need help with, is validating password strings for the new user function. Simply, the add user form passes all the info to the SQL db. I ran into the problem of password strings containing symbols not wanting to work at all, though it WOULD pass to the db just fine, wouldn't allow logging in with them. Also, if the initial character was a number, it didn't like that either. As long as these two conditions weren't there, then it works perfectly. Creates the user and their credentials are READY for use in <30s. But if it starts with numbers or contains symbols - merp. no work.
So, the thing that I'm going for is one of two option; A) a functioning string VALIDATION technique that find prohibited characters in string, and checks to make sure the first char is alpha only; B) a way to get it to accept any password regardless of what characters it contains (no nulls and 6+ char).
I started trying us instr and like in if statements, but neither of them works right. They don't stop the process or EVEN display their msgbox correctly. Even though they should, they don't.
Anyway, all help is appreciated. Alright, I partially figured this out... just a little more tuning needed.
Code: [Select]Option Compare Database 'textbox check function Public Function IsAlphaNum(ByVal sString As String) As Boolean If Nos sString Like "*[!0-9A-z]*" Then IsAlphaNum = True ' This is the part that needs tuning. If Not sString Like "#*" Then IsAlphaNum = True 'Basically this is attempting to prohibit the first char from being a number. End Function '---------------------- Private Sub Test_Click() If IsAlphaNum(Me.BoxTest) = False Then MsgBox "Password must be alphanum and can't start with a num." Exit Sub Else MsgBox "password accepted." End If End Sub
The code, as shown above, doesn't stop numbers from being the first char. It blocks symbols just fine, but not initial numbers... I've tried a few different methods to get it to accept both if statements, but it hasn't wanted to work. I've tried Or, And, AndAlso (which i think it correct), and even a nested-if... none of them seem to want to work, so i must be doing something wrong...
Thanks in advance. - kyle_engineerWow... so sorry I solved my own problem... but here's what worked for me! I hope people in the community use this.
Code: [Select]Option Compare Database '--------------------------------------------------------- 'textbox check function Public Function IsAlphaNum(ByVal sString As String) As Boolean Dim strFirstChar As String If Not sString Like "*[!0-9A-z]*" Then IsAlphaNum = True strFirstChar = Left(Me.BoxPassword, 1) If IsNumeric(strFirstChar) Then IsAlphaNum = False End Function '---------------------- Private Sub Test_Click() If IsAlphaNum(Me.BoxPassword) = False Then MsgBox "Password must be alphanum and can't start with a num." Exit Sub Else MsgBox "password accepted." End If End Sub
|