Results 1 to 5 of 5
  1. #1
    injanib is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jan 2011
    Posts
    67

    input Validation


    I have an unbound field that is used to enter for a new password.

    On the event, before the input is encrypted and written into the table, I would like to check for the string to make sure it contains at least one upper case, one lower case and one number.

    How can I go about doing this?

    Thanks in advance.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    Don't think will be easy because VBA and Access are not case sensitive - "jrh" Like "*[A-Z]*" will return True

    You need to test the entry against 3 criteria. The number part is easy enough
    If Not stringIn Like "*[0-9]*" Then
    MsgBox "Not a valid password. Try again."
    End If

    Here is possible way to check for letter case. Write a custom function that can be called in the above If Then. The function would take the user entry as input argument, convert each character to ASCII equivalent and test if the value falls within the ASCII range for Upper or Lower Case or a Number.

    Number: ASC(strChar) >= 48 And ASC(strChar) <= 57
    Lower Case: ASC(strChar) >= 65 And ASC(strChar) <= 90
    Upper Case: ASC(strChar) >= 97 And ASC(strChar) <= 122

    Have 3 boolean variables in the code that would be set to True if related condition met. If all 3 True then the function returns True (valid password) otherwise False (invalid password).
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    injanib is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jan 2011
    Posts
    67
    thanks, but doesn't the Asc function return the ASCii equivalent of the first character in a string. I tried this, but the function returns falls no matter what, and I think it is because each case looks for the related condition in the first character of the string.

    Any other suggestions?

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,849
    June gave you great advice.
    Here's some sample code to show how it works. You'll have to change it to make it a function. Sometimes passwords must be a minimum length as well.

    Sub checkAlphaNumberAndLower()
    'Number: ASC(strChar) >= 48 And ASC(strChar) <= 57
    'Lower Case: ASC(strChar) >= 65 And ASC(strChar) <= 90
    'Upper Case: ASC(strChar) >= 97 And ASC(strChar) <= 122
    Dim str As String
    Dim strChar As String
    Dim i As Integer
    Dim LowerFound As Boolean
    Dim UpperFound As Boolean
    Dim NumericFound As Boolean
    On Error GoTo checkAlphaNumberAndLower_Error

    LowerFound = False
    UpperFound = False
    NumericFound = False

    str = "BAD" '"Go0d"
    'UpperCheck
    For i = 1 To Len(str)
    strChar = Mid(str, i, 1)
    If Asc(strChar) >= 97 And Asc(strChar) <= 122 Then
    UpperFound = True
    Exit For
    Else
    End If
    Next

    'LowerCheck
    For i = 1 To Len(str)
    strChar = Mid(str, i, 1)
    If Asc(strChar) >= 65 And Asc(strChar) <= 90 Then
    LowerFound = True
    Exit For
    Else
    End If
    Next

    'NumericCheck
    For i = 1 To Len(str)
    strChar = Mid(str, i, 1)
    If Asc(strChar) >= 48 And Asc(strChar) <= 57 Then
    NumericFound = True
    Exit For
    Else
    End If
    Next

    'Check Results
    If UpperFound = True And _
    LowerFound = True And _
    NumericFound = True Then
    MsgBox str & " is a valid password "
    Else
    MsgBox str & " is NOT A VALID PASSWORD !!"
    End If

    On Error GoTo 0
    Exit Sub

    checkAlphaNumberAndLower_Error:

    MsgBox "Error " & Err.number & " (" & Err.Description & ") in procedure checkAlphaNumberAndLower of Module AWF_Related"
    End Sub

  5. #5
    injanib is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jan 2011
    Posts
    67
    Ahh! so that was the trick to make it search the entire length of the string. Sorry I wasn't smart enough to implement June7's suggestion the right way. But this works great, and I also included the validation rule for the length of the password and also the presence of special character in it in the function. It works like magic. Thanks June7 and Orange.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Data Validation using VBA
    By Cheshire101 in forum Programming
    Replies: 3
    Last Post: 05-10-2011, 08:43 AM
  2. Input Mask/Validation rule
    By SMAlvarez in forum Access
    Replies: 0
    Last Post: 04-11-2011, 07:27 PM
  3. Replies: 0
    Last Post: 03-18-2011, 06:38 AM
  4. Validation problems...
    By dbDamo in forum Forms
    Replies: 1
    Last Post: 05-15-2009, 12:43 PM
  5. Validation and Input masks
    By Santi in forum Access
    Replies: 3
    Last Post: 03-26-2009, 10:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums