DD
DevDash

Regex for 6-Digit PIN

Regex Pattern

^\d{6}$

Six-digit PIN code

Quick Answer

The regex pattern for 6-digit pin is `^\d{6}$`. Six-digit PIN code. This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.

Test Examples

InputResult
123456✓ Matches
000000✓ Matches
999999✓ Matches
12345✗ No match
1234567✗ No match
abcdef✗ No match

Code Examples

javascript

const regex = /^\d{6}$/;
const isValid = regex.test(value);

python

import re
pattern = r'^\d{6}$'
if re.match(pattern, value):
    print("valid")

ruby

pattern = /^\d{6}$/
if value =~ pattern
  puts "valid"
end

php

if (preg_match('/^\d{6}$/', $value)) {
    echo "valid";
}

java

String pattern = "^\\d{6}$";
boolean isValid = value.matches(pattern);

Frequently Asked Questions

Related Regex Patterns

Want API access + no ads? Pro coming soon.