• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 408
  • Last Modified:

If string contains 5+ uPPerCASE characters then redirect

I need to check a string to see if it contains >5 UppER CASE characters and or if it contains numbers. IF either of these are tru then redirect to a new page.

Please help
dim regex
set regex = new regexp
      regex.global = true
      regex.pattern = "[^A-Z]"
set regmatch = regex.execute(strFname)
if regmatch.count >=5 then
  Response.Write "<script type='text/javascript'>alert('5+ Uppercase characters');</script>"
else
    Response.Write "<script type='text/javascript'>alert('Your Good');</script>"
end if

Open in new window

0
pGustafson
Asked:
pGustafson
  • 4
  • 2
1 Solution
 
CCongdonCommented:
Does this do what you need?
Dim hasNumber
Dim has5Caps
Dim capCounter
hasNumber = False
has5Caps = False
capCounter = 0
For X = 1 to Len(Fname)
  If (IsNumeric(Mid(Fname,X,1))) Then hasNumber = True
  If (StrComp(UCase(Mid(Fname,X,1)), Mid(Fname,X,1), 0) = 0) Then capCounter = capCounter +1
Next
If ((capCounter >= 5) OR hasNumber) Then Response.Redirect("targetPage.asp")

Open in new window

0
 
CCongdonCommented:
Quick explanation if you are interested....
Lines 1-3: Initialize variables
Lines 4-6: Set default values for these variables
Line 7: Start of For Next loop. Goes from 1 to however many characters in the string.
Line 8: Check the character at position 'X' in the string. Is it a number? If so, make our hasNumber flag true.
Line 9: Take the character at position X and make it an upper case.... compare it to the original character in position X. Are they a case sensitive match? If so, increment our counter (capCounter) keeping track of capitals.
Line 10: End of loop
Line 11: Check the capCounter and the hasNumber flag. If the flag is raised or capCounter is greater than/equal to 5, redirect client to a new page.
 
0
 
CCongdonCommented:
I couldn't resist. I re-wrote this a little bit. Makes it a little more streamlined. It also breaks out of the loop at the soonest opportunity possible, that way if you feed it 100 characters, it doesn't necessarily have to check them all. The two control variables (Max number of caps and target redirect page) have been moved to the top to make them more visible and easier to change.

Dim exitPage : exitPage = False
Dim capsCounter : capsCounter = 0
Dim maxCaps : maxCaps = 5
Dim targetPage : targetPage = "targetpage.asp"
 
For X = 1 to Len(Fname)
  If (IsNumeric(Mid(Fname,X,1))) Then exitPage = True
  If (StrComp(UCase(Mid(Fname,X,1)), Mid(Fname,X,1), 0) = 0) Then
    capsCounter = capsCounter +1
    If (capsCounter >= maxCaps) Then exitPage = True
  End If
  If exitPage Then Exit For
Next
If exitPage Then Response.Redirect(targetPage)
 

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
pGustafsonAuthor Commented:
Thank you so much... That worked awesome.
0
 
pGustafsonAuthor Commented:
That's awesome... I wonder if there is a way to have it check multiple strings for a total maXcap number of 5
0
 
CCongdonCommented:
You could put your string in an array then iterate through the array. Each item in the array would be matched against the For...Next loop.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now