2

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:

  • 10 alphanumerical characters, any case.
  • A forward slash
  • Numbers, 1-9 digits long
  • A forward slash
  • 10 alphanumerical characters, any case.
Cheran Shunmugavel
  • 8,319
  • 1
  • 33
  • 40
TheCarver
  • 19,391
  • 25
  • 99
  • 149

2 Answers2

1

"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.

Tomalak
  • 332,285
  • 67
  • 532
  • 628
1

Please try with below expression:

^(([A-z\d]{10})/(\d{1,9})/([A-z\d]{10}))$
Elias Hossain
  • 4,410
  • 1
  • 19
  • 33