[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Evaluate if a string is uppercase in classic ASP (vbScript) v2

Posted on 2008-11-14
10
Medium Priority
?
1,650 Views
Last Modified: 2012-06-21
Hi.
An expert kindly helped me with this task this morning, however I'm finding an issue.
In the code below if targetString is "HELLO" then it works perfectly... However if

targetString = "HeLLO"

TRUE is also still produced and it should be FLASE?

Any Ideas?
<%
Dim re, targetString
Set re = New RegExp
With re
  .Pattern = "^[A-Z].*$"
  .Global = True
  .IgnoreCase = Flase
End With
targetString = "HeLLO"
 
response.write (re.Test(targetString))
%>

Open in new window

0
Comment
Question by:TheAnvilGroup
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 18

Expert Comment

by:ChetOS82
ID: 22959542
Your regular expression looks good, so I don't know why it doesn't work.  That being said, I wouldn't have used this method to determine if the string is uppercase.

In VBScript, string comparison is already case-sensitive.  So I just do:
<%
dim targetString
targetString = "HeLLO"
response.write (targetString = UCASE(targetString))
%>

Open in new window

0
 
LVL 18

Expert Comment

by:ChetOS82
ID: 22959568
Ok, the reason this isn't working is because your pattern includes a period, which is essentially asking "Is the first letter uppercase, followed by any number of characters".

You need to remove the period from the pattern.
0
 
LVL 18

Expert Comment

by:ChetOS82
ID: 22959600
Sorry about the triple post :)

That period is also causing the regexp to match numbers and special characters as well.  A targetString of "He1|0" would also evaluation to true.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 76

Expert Comment

by:David Lee
ID: 22959638
Hi, TheAnvilGroup.

I'm not much into regular expressions, so I'm not sure whey that code isn't working.  However, but we can test if the string is all uppercase in a much simpler fashion.
Dim strTest
strTest = "HeLLO"
response.write (UCase(strTest) = strTest)

Open in new window

0
 
LVL 76

Expert Comment

by:David Lee
ID: 22959643
Ignore my post.  I refreshed the question before posting and there were no comments at all.  Then I post and asll the otehr comments appear.
0
 
LVL 7

Expert Comment

by:aherps
ID: 22964001

<%
Dim re, targetString
Set re = New RegExp
With re
  .Pattern = "^[A-Z]*$"
  .Global = True
  .IgnoreCase = Flase
End With
targetString = "HeLLO"
 
response.write (re.Test(targetString))
%>

Open in new window

0
 
LVL 82

Expert Comment

by:hielo
ID: 22964501
two things:
1. >>.Pattern = "^[A-Z].*$"
get rid of the perios

2. .IgnoreCase = Flase
should be False
0
 
LVL 82

Expert Comment

by:hielo
ID: 22964515
correction, the correct pattern is:
  .Pattern = "^[A-Z]+$"

if you leave
.Pattern = "^[A-Z]*$"

and then supply this:
targetString = ""

it will evaluate to true, which is not what you want. Use:
  .Pattern = "^[A-Z]+$"
0
 
LVL 82

Accepted Solution

by:
hielo earned 2000 total points
ID: 22978345
In case you missed it, the pattern should be using a + symbol, NOT a *
0
 
LVL 82

Expert Comment

by:hielo
ID: 22984327
glad to help
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question