AEP
AEP

Reputation: 31

Regular Expression voodoo in ASP

Argh it's a good thing I don't pay my salary on days like this. I copied some regex patterns from my client side Javascript to server side ASP and the email pattern works no probs but an identical function for the password pattern has cost my boss 6 hours today (our little secret).

Function validatePassword(strPass)
  Dim regEx
  Set regEx = new RegExp

  regEx.IgnoreCase = false
  regEx.global = false
  regEx.Pattern = "^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,10}$"
  ValidatePassword = regEx.Test(strPass)
End Function

It's a simple 1 upper, 1 lower, 1 digit, 6-10 chars pattern and there's zero doubt that it matches as it should but ex. 3DMM9igggg returns false, but gDMM9igggg returns true. It works fine in JS, here: http://www.regular-expressions.info/javascriptexample.html, and in a couple other testers I tried.

WTF? Can somebody lend me their eyes for a sec?

Thanks

Upvotes: 2

Views: 278

Answers (1)

Jonathan M
Jonathan M

Reputation: 17451

It could be that your particular ASP regex engine does not support lookaheads in the same way as the javascript engine. That is the case with some engines, per the 4th paragraph under advanced topics on this link: http://msdn.microsoft.com/en-us/library/ms972966.aspx#regexnet_topic13

There's also an example of a lookahead-based password test in the 5th paragraph.

If the engine is indeed the problem, a simple-yet-inefficient solution is to run 3 tests: one for an upper, one for a lower, one for a digit with a length test included.

Upvotes: 2

Related Questions