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

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

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
TheAnvilGroup
Asked:
TheAnvilGroup
  • 4
  • 3
  • 2
  • +1
1 Solution
 
ChetOS82Commented:
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
 
ChetOS82Commented:
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
 
ChetOS82Commented:
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
David LeeCommented:
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
 
David LeeCommented:
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
 
aherpsCommented:

<%
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
 
hieloCommented:
two things:
1. >>.Pattern = "^[A-Z].*$"
get rid of the perios

2. .IgnoreCase = Flase
should be False
0
 
hieloCommented:
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
 
hieloCommented:
In case you missed it, the pattern should be using a + symbol, NOT a *
0
 
hieloCommented:
glad to help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

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