Regex for Positive Integer
Regex Pattern
^[1-9]\d*$Integers greater than zero (no leading zeros)
Quick Answer
The regex pattern for positive integer is `^[1-9]\d*$`. Integers greater than zero (no leading zeros). This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.
Test Examples
| Input | Result |
|---|---|
| 1 | ✓ Matches |
| 42 | ✓ Matches |
| 12345 | ✓ Matches |
| 999999 | ✓ Matches |
| 0 | ✗ No match |
| -1 | ✗ No match |
| 1.5 | ✗ No match |
| 01 | ✗ No match |
Code Examples
javascript
const regex = /^[1-9]\d*$/; const isValid = regex.test(value);
python
import re
pattern = r'^[1-9]\d*$'
if re.match(pattern, value):
print("valid")ruby
pattern = /^[1-9]\d*$/ if value =~ pattern puts "valid" end
php
if (preg_match('/^[1-9]\d*$/', $value)) {
echo "valid";
}java
String pattern = "^[1-9]\\d*$"; boolean isValid = value.matches(pattern);
Frequently Asked Questions
Related Regex Patterns
Non-negative Integer
Zero or positive integer
Decimal Number
Optionally signed decimal number
Hex Color Code
3 or 6-digit hex color with optional #
USD Currency
US dollar amount with optional $ and thousands separators
Email Address
Validates a standard email address format
Email (RFC 5322 Compliant)
RFC 5322 compliant email validation with label length limits