Regex for Checking for at Least One Digit
Tests whether a string contains at least one numeric digit anywhere.
Published October 11, 2026
This regex tests whether a string contains at least one digit anywhere.
How the pattern works
Breaking the pattern down: \d = any digit.
Test your regex against both matching and non-matching inputs; use the Regex tool on this site to experiment live.
Pattern tests
/\d/
✓ 'abc1'
✓ '42'
✗ 'abc'
✗ '!?'
Practical examples
The pattern
const re = /\d/Test it
const re = /\d/
re.test('abc1') // true
re.test('42') // true
re.test('abc') // false
re.test('!?') // falseIn Python
import re
re.search(r'\d', text)Common mistakes
- Using ^\d$ (only a single-digit string).
- Locale digits.
- Doing it in lookahead chains unnecessarily.
Key takeaways
- Anchors (^ and $) make the whole string match instead of a part of it.
- Regex checks format only; verify data separately when it matters.
- Test with valid and invalid samples.
FAQ
Use a lookahead?
For combined rules: (?=.*\d).
Where can I test this pattern?
Use the Regex Tester on this site, or regex101.com.