Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 801595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:27:57+00:00 2026-05-14T23:27:57+00:00

I found the answer to this, but it’s a bit of a gotcha so

  • 0

I found the answer to this, but it’s a bit of a gotcha so I wanted to share it here.

I have a regular expression that validates passwords. They should be 7 to 60 characters with at least one numeric and one alpha character. Pretty standard. I used positive lookaheads (the (?= operator) to implement it:

(?=^.{7,60}$)(?=.*[0-9].*)(?=.*[a-zA-Z].*)

I checked this expression in my unit tests using Regex.IsMatch(), and it worked fine. However, when I use it in a RegularExpressionValidator, it always fails. Why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T23:27:58+00:00Added an answer on May 14, 2026 at 11:27 pm

    It’s strange that I’ve never run into this before, but it turns out that the RegularExpressionValidator doesn’t use Regex.IsMatch or JavaScript’s Regex.test() — it checks for a capturing match that exactly equals the full tested value. Here’s the relevant JS code:

    var rx = new RegExp(val.validationexpression);
    var matches = rx.exec(value);
    return (matches != null && value == matches[0]);
    

    So if the expression is all lookaheads (which match positions, not the actual text), it will fail. This is clearer with the example of an expression that only partially matches, e.g. with \d{5}, the value “123456” would fail. It’s not just that it adds “^$” around your expression and does an IsMatch. Your expression actually has to capture.

    The fix in my case is this expression:

    (?=^.{7,60}$)(?=.*[0-9].*).*[a-zA-Z].*
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I looked around but haven't found an answer to this. I have a CentOS
Searched a lot about this problem but never found a answer, that solved it.
I haven't found a clear answer to this question (but have determined the HTML
I couldn't found this answer in Stackoverflow, but I have two domains and two
I found this answer , which is great. But what If I also have
I have been doing some research on this but found no clear answer. The
I have searched this question, and found an answer in MySQL but this is
I found this answer and I try to do follow that, but It didn't
I found this answer, but it is far from a simple code snippet that
I wanted to create some clickable PowerShell scripts, and I found this answer that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.