Click to See Complete Forum and Search --> : [RESOLVED] Character validation in form
Danbabe
03-31-2010, 04:59 PM
Hi folks,
I need to develop a form where the user can change their password. I would like to find a way of validating their entry to have at least 1 capital letter, 1 uppercase character and at least 1 number.
I also want to make the length at least 8 characters and think this should work:
If len(fPassword) < 8 Then
blah blah
End If
Any ideas on the other validation entries?
Many thanks
Dan
jonmaster
04-01-2010, 12:08 PM
You can use regular expression try from regexlib.com
Danbabe
04-01-2010, 04:06 PM
I am sorry jonmaster but I have no idea what a regular expression is. I have looked at the site you recommended but it does not explain how I would impliment any of the code on their site.
I found an 'expression' that matched my needs so thank you but no idea how to even start getting this to work on a site.
Can anyone help please?
Dan
Danbabe
04-01-2010, 04:34 PM
This is the code I have tried but dows not work:
'Validate the password
Dim checkCaps, checkLCase, checkNumbs
checkCaps = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
checkLCase = "abcdefghijklmnopqrstuvwxyz"
checkNumbs = "0123456789"
If instr(fPassword, checkCaps) = 1 Then
If instr(fPassword, checkLCase) = 1 Then
If instr(fPassword, checkNumbs) = 1 Then
action = 1
Else
action = 2
End If
Else
action = 2
End If
Else
action = 2
End If
If len(fPassword) < 8 Then
action = 2
End If
Concept is if action = 1 then, add to the database, if not, repond back to the page advising user password is not compliant
Any ideas folks
Thanks
Dan
yamaharuss
04-01-2010, 05:50 PM
What's the difference between 1 capital letter and 1 uppercase character??
yamaharuss
04-01-2010, 06:06 PM
If you require upper AND lower AND numeric then this is all you need:
Function isValid(val)
dim isValidE
dim regEx
isValidE = True
set regEx = New RegExp
regEx.IgnoreCase = False
regEx.Pattern = "^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,20}$"
isValidE = regEx.Test(val)
isValid = isValidE
End Function
If isValid(fPassword) Then
blah blah
End If
You can change the number 20 to whatever you max length is.
Danbabe
04-01-2010, 06:45 PM
Thanks everyone who helped but I managed to manipulate the code on http://www.codefixer.com/codesnippets/VBScript_Email_Validation.asp and came up with:
'Validate the password
Dim iLoopCounter, passwordChar, action
Dim checkLcase, checkUcase, checkNum
Dim totalLcase, totalUcase, totalNum
action = 1
checkLcase = "abcdefghijklmnopqrstuvwxyz"
checkUcase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
checkNum = "0123456789"
totalLcase = 0
totalUcase = 0
totalNum = 0
'Count password characters to meet above accepted characters
For iLoopCounter = 1 to Len(fPassword)
passwordChar = mid(fPassword, iLoopCounter, 1)
'Check lowercase
If inStr(checkLcase, passwordChar) and Not IsNumeric(passwordChar) = 1 Then
totalLcase = totalLcase + 1
End If
'Check uppercase
If inStr(checkUcase, passwordChar) and Not IsNumeric(passwordChar) = 1 Then
totalUcase = totalUcase + 1
End If
'Check numbers
If inStr(checkNum, passwordChar) and Not IsNumeric(passwordChar) = 1 Then
totalNum = totalNum + 1
End If
Next
If totalLcase = 0 Then
action = 2
End If
If totalUcase = 0 Then
action = 3
End If
If totalNum = 0 Then
action = 4
End If
If len(fPassword) < 8 Then
action = 5
End If
Thanks again all
Dan
yamaharuss
04-02-2010, 07:18 AM
Wow! Talk about taking the long way home.