Reputation: 13
I have a question on Classic ASP regarding validating a string's first 3 letters to be uppercase while the last 4 characters should be in numerical form using regex.
For e.g.:
dim myString = "abc1234"
How do I validate that it should be "ABC1234"
instead of "abc1234"
?
Apologies for my broken English and for being a newbie in Classic ASP.
Upvotes: 0
Views: 515
Reputation: 16321
@ndn has a good regex pattern for you. To apply it in Classic ASP, you just need to create a RegExp
object that uses the pattern and then call the Test()
function to test your string against the pattern.
For example:
Dim re
Set re = New RegExp
re.Pattern = "^[A-Z]{3}.*[0-9]{4}$" ' @ndn's pattern
If re.Test(myString) Then
' Match. First three characters are uppercase letters and last four are digits.
Else
' No match.
End If
Upvotes: 2
Reputation: 36110
^[A-Z]{3}.*[0-9]{4}$
Explanation:
^$
(start and end of string) to ensure you are matching everything[A-Z]
- gives you all capital letters in the English alphabet{3}
- three of those.*
- optionally, there can be something in between (if there can't be, you can just remove this)[0-9]
- any digit{4}
- 4 of thoseUpvotes: 1