DD
DevDash

Regex for Strong Password (12+ chars)

Regex Pattern

^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*()_+=-]).{12,}$

Strong password: 12+ characters with uppercase, lowercase, digit, and special character

Quick Answer

The regex pattern for strong password (12+ chars) is `^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*()_+=-]).{12,}$`. Strong password: 12+ characters with uppercase, lowercase, digit, and special character. This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.

Test Examples

InputResult
MyStr0ng!Pass✓ Matches
Secure#Pass123✓ Matches
C0mpl3x@Passw0rd✓ Matches
short1!A✗ No match
nouppercase1!✗ No match
NOLOWERCASE1!✗ No match
NoSpecial123✗ No match

Code Examples

javascript

const regex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*()_+=-]).{12,}$/;
const isValid = regex.test(value);

python

import re
pattern = r'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*()_+=-]).{12,}$'
if re.match(pattern, value):
    print("valid")

ruby

pattern = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*()_+=-]).{12,}$/
if value =~ pattern
  puts "valid"
end

php

if (preg_match('/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*()_+=-]).{12,}$/', $value)) {
    echo "valid";
}

java

String pattern = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[!@#$%^&*()_+=-]).{12,}$";
boolean isValid = value.matches(pattern);

Frequently Asked Questions

Related Regex Patterns

Want API access + no ads? Pro coming soon.