Regex for 6-Digit OTP Code
Regex Pattern
^\d{6}$Six-digit one-time password (OTP)
Quick Answer
The regex pattern for 6-digit otp code is `^\d{6}$`. Six-digit one-time password (OTP). This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.
Test Examples
| Input | Result |
|---|---|
| 123456 | ✓ Matches |
| 000001 | ✓ 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"
endphp
if (preg_match('/^\d{6}$/', $value)) {
echo "valid";
}java
String pattern = "^\\d{6}$";
boolean isValid = value.matches(pattern);Frequently Asked Questions
Related Regex Patterns
Strong Password
At least 8 chars with uppercase, lowercase, digit, and special character
Password 12+ Characters
At least 12 characters with uppercase, lowercase, and digit
Strong Password (12+ chars)
Strong password: 12+ characters with uppercase, lowercase, digit, and special character
4-Digit PIN
Four-digit PIN code
6-Digit PIN
Six-digit PIN code
Email Address
Validates a standard email address format