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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:49:16+00:00 2026-06-07T00:49:16+00:00

I use java and a regexp. I’ve made a regexp for password validation :

  • 0

I use java and a regexp.

I’ve made a regexp for password validation :

String PASSWORD_PATTERN_ADVANCED = "^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[\\\\@#$¤£µ§%&<>,.!:?;~{-|`'_^¨éèçàù)=}()°\"\\]\\[²³*/+]).{8,20}$";

or without the extra slash :

^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[\\@#$¤£µ§%&<>,.!:?;~{-|`'_^¨éèçàù)=}()°"\]\[²³*/+]).{8,20}$

whuch means (i may be wrong): at least one digit / at least one lowercase / at least one uppercase / at least one of the special chars listed / with a minimum total length of 8 and a max of 20…

made a test case generating password for success and failure…

success -> OK, all passed
failure -> Almost OK …

The only password that fails to fail 😀 are the ones with space in it like :

 iF\ !h6 2A3|Gm 
¨I O7 gZ2%L£k vd~39 
2< A Uw a7kEw6,6S^ 
cC2c5N#  
6L kIw~ Béj7]5 
ynRZ #44ç 
9A `sè53Laj A 
s²R[µ3  9UrR q8n 

I am puzzled.

Any thoughts to make it works ?

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-06-07T00:49:20+00:00Added an answer on June 7, 2026 at 12:49 am

    A regex may not be the right tool for the job here.

    Regexes are best suited for matching patterns; what you’re describing isn’t really a pattern, per se; it’s more of a rule set. Sure, you may be able to create some regex that helps, but it’s a really complex and opaque piece of code which make maintenance a challenge.

    A method like this might be a better fit:

    public boolean isValidPassword(String password) {
        boolean containsLowerCase;
        boolean containsUpperCase;
        boolean containsInvalid;
        boolean containsSpecialChar;
        boolean containsDigit;
    
        for(char c: password.toCharArray()) {
            containsLowerCase   ||= Character.isLowerCase(c);
            containsUpperCase   ||= Character.isUpperCase(c);
            containsDigit       ||= Character.isDigit(c); 
            containsSpecialChar ||= someMethodForDetectingIfItIsSpecial(c);
    
        }
    
        return  containsLowerCase &&
                containsUpperCase &&
                containsSpecialChar &&
                containsDigit &&
                !containsInvalid &&
                password.length >=8 && password.length <=20;
    
    }
    

    You’d need to decide the best way to detect a special character (specialCharArray.contains(c), regular expression, etc).

    However, this approach would make adding new rules a lot simpler.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a regex to use in Java to replace a String with UNKNOWN
Is there a way to use a Java regex to change a String to
Trying to use Java's regexp I want to match /app, /app/.* , but not
The string methods in Java that use the regular expressions need to escape some
I have a String in this format: mydb://<user>:<password>@<host>:27017 And I would like to use
I use java 7, and I create a varargs method public class JavaApplicationTest {
i use java reflections to get methods used in a class.I also want to
How can I use java reflection or similar to find project name by just
Description: If we use java objects jruby get permgen too: System.out.println(Initialazing..); //Spring applicaton context
Is it possible to use Java FutureTask with a Spring TaskExecutor to get a

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.