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 7626435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:19:28+00:00 2026-05-31T05:19:28+00:00

I have a problem with my matches . I have a field that that

  • 0

I have a problem with my matches. I have a field that that SHOULD accept a value that may contain any combination of alphanumeric and special characters. I have a code that works fine when the input is a 1) combination of alphanumeric and special characters, and 2) alphanumeric. But if the input contains a combination of either 1) number and special characters ONLY without alphabet or 2) alphabet and special characters ONLY without number, I got an error on my matches. What I wanted to do is to create a matches that best works on the following input combinations:

1) alphabet+number
2) alphabet+special character
3) alphabet+number+special character
4) number+special character

This is my code:

matches: /^(?=.*[0-9]+.*)(?=.*[a-zA-Z]+.*)[0-9a-zA-Z_\[\]\\\^\$\.\|\?\*\+\(\)~!@#%&-=]{8,}$/

I need your suggestions!
Thanks!

  • 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-31T05:19:28+00:00Added an answer on May 31, 2026 at 5:19 am

    It’s because your positive lookahead requires both a [0-9] to be present and a [a-zA-Z] to be present.

    Try reducing this to one single lookahead, which just specifies that at least one of [0-9] and [a-zA-Z] be present:

    matches: /^(?=.*[0-9a-zA-Z])[0-9a-zA-Z_\[\]\\\^\$\.\|\?\*\+\(\)~!@#%&-=]{8,}$/
    

    Furthermore, you can improve on the efficiency of the regex by modifying the .* in your lookahead to be [^0-9a-zA-Z]*: that way the lookahead matches the first alphanumeric it finds and then stops, preventing needless scanning:

    matches: /^(?=[^0-9a-zA-Z]*[0-9a-zA-Z])[0-9a-zA-Z_\[\]\\\^\$\.\|\?\*\+\(\)~!@#%&-=]{8,}$/
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a dilemma. I have a field hashedX that is a hashed/salted value
I have a two-step search problem. First I want to see if any matches
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with fancybox. I want to write a function that will run
I have problem with cakephp's Session->write method. If I set a value like $_SESSION['..']
I have a search form field that I want to compare with multiple columns
I have a value I am trying to index that looks like this: Test
I have a simple sounding problem according highlighting of a field with elasticsearch version
I am having a problem with a generic regex that matches (sort of) a
Problem I have a protobuf message definition with a MessageType field, which is an

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.