LogoReturn to Home RegEx
Integrations
All integrations
AWS API
AWS Lambda
DynamoDB
Oracle
Redshift
Snowflake
GraphQL
Supabase
Twilio
Azure Blob Storage
Slack
SendGrid
Generic HTTP API
AWS S3
Stripe
Microsoft SQL
Salesforce
PostgreSQL
MySQL
MongoDB
HubSpot
Google Sheets
Google BigQuery
Firebase
Airtable
Integrations
About UI Bakery
Log in
Request UI Bakery demo
RegEx library
Email regex Java
Phone number regex Java
IP address regex Java
Date regex Java
URL regex Java
Numbers only regex (digits only) Java
UUID regex Java
Regex match words Java
ZIP code regex Java
GUID regex Java
Password regex Java
HTML regex Java
SSN regex Java
XML regex Java
Mac address regex Java
Street address regex Java

Password regex Java

Password regular expression can be used to verify that a password provided is strong enough to provide better protection against bot brute force attacks. This method, however, does not guarantee that a password will have enough entropy to be completely safe.

Discover UI Bakery – an intuitive visual internal tools builder. Try it now!
JavaScript
Python
Java
C#
PHP

Strong password regex

The regular expression below cheks that a password:

  • Has minimum 8 characters in length. Adjust it by modifying {8,}
  • At least one uppercase English letter. You can remove this condition by removing (?=.*?[A-Z])
  • At least one lowercase English letter.  You can remove this condition by removing (?=.*?[a-z])
  • At least one digit. You can remove this condition by removing (?=.*?[0-9])
  • At least one special character,  You can remove this condition by removing (?=.*?[#[email protected]$%^&*-])
Pattern.compile("^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#[email protected]$%^&*-]).{8,}$")
Test it!
/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#[email protected]$%^&*-]).{8,}$/

True

False

Enter a text in the input above to see the result

Example code in Java:

import java.util.regex.Pattern;

public class Main {

    public static void main(String []args) {
        // Validate strong password
        boolean isMatch = Pattern.compile("^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#[email protected]$%^&*-]).{8,}$")
               .matcher("-Secr3t.")
               .find(); 
        System.out.println(isMatch); // prints true
    }
}
Test it!

True

False

Enter a text in the input above to see the result

Test it!

True

False

Enter a text in the input above to see the result

Notes on password regex validation

While this regex validation is better than nothing, in situations when additional security is needed you should also check the password entered for a set of commonly used passwords like:

  • .Qwerty1
  • !Q1w2e3r4
  • etc

One good list can be found here.

Create an internal tool with UI Bakery

Discover UI Bakery – an intuitive visual internal tools builder.

Try it now