DD
DevDash

Regex for AWS Account ID

Regex Pattern

^\d{12}$

AWS account ID — exactly 12 digits

Quick Answer

The regex pattern for aws account id is `^\d{12}$`. AWS account ID — exactly 12 digits. This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.

Test Examples

InputResult
123456789012✓ Matches
000000000000✓ Matches
999999999999✓ Matches
12345678901✗ No match
1234567890123✗ No match
abcdefghijkl✗ No match

Code Examples

javascript

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

python

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

ruby

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

php

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

java

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

Frequently Asked Questions

Related Regex Patterns

Want API access + no ads? Pro coming soon.