DD
DevDash

Regex for Password 12+ Characters

Regex Pattern

^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{12,}$

At least 12 characters with uppercase, lowercase, and digit

Quick Answer

The regex pattern for password 12+ characters is `^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{12,}$`. At least 12 characters with uppercase, lowercase, and digit. This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.

Test Examples

InputResult
MyPassword123✓ Matches
LongEnough4Me✓ Matches
TwelveChars1A✓ Matches
Short1A✗ No match
alllowercase1✗ No match
ALLUPPER123✗ 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.