Reputation: 19723
I am trying to validate a querystring coming from an email activation link, written in Classic ASP.
The querystring input contains numbers, letters and 2 forward slashes. Like this: G3hEus87YK/6738/HE347sxThH
and I need to validate it, checking that only numbers, letters and slashes have been used.
The numbers in between the slashes could be 1-9 digits long, here I used 4 as an example but there are always 10 alphanumerical characters before the slash and 10 after.
I have done this so far, that will run the check, but I'm not sure which pattern to give it!
Function validateToken(token)
Set regEx = New RegExp
regEx.IgnoreCase = True
regEx.Pattern = "???????????"
validateToken = regEx.Test(Trim(Request.QueryString("token")))
End Function
My attempt for numbers and letters only would be, [A-z][0-9]
, but looking for 2 slashes confuses me. How can I look for slashes too?
I suppose if I wrote the pattern in pure English, it would read:
Upvotes: 2
Views: 7406
Reputation: 4469
Please try with below expression:
^(([A-z\d]{10})/(\d{1,9})/([A-z\d]{10}))$
Upvotes: 1
Reputation: 338326
"there are always 10 alphanumerical characters before the slash and 10 after"
Ten alphanumerical characters are [a-z\d]{10}
, assuming that IgnoreCase
is enabled.
"The numbers in between the slashes could be 1-9 digits long"
That would be \d{1,9}
, so the final pattern is fairly simple:
regEx.Pattern = "^[a-z\d]{10}/\d{1,9}/[a-z\d]{10}$"
The ^
and $
disallow anything before or after the pattern.
Upvotes: 1