Regex for Percentage Value
Regex Pattern
^-?\d+(?:\.\d+)?%$Numeric percentage with % sign
Quick Answer
The regex pattern for percentage value is `^-?\d+(?:\.\d+)?%$`. Numeric percentage with % sign. This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.
Test Examples
| Input | Result |
|---|---|
| 100% | ✓ Matches |
| 50.5% | ✓ Matches |
| -3.14% | ✓ Matches |
| 0% | ✓ Matches |
| 100 | ✗ No match |
| 50%50 | ✗ No match |
| % only | ✗ No match |
Code Examples
javascript
const regex = /^-?\d+(?:\.\d+)?%$/; const isValid = regex.test(value);
python
import re
pattern = r'^-?\d+(?:\.\d+)?%$'
if re.match(pattern, value):
print("valid")ruby
pattern = /^-?\d+(?:\.\d+)?%$/ if value =~ pattern puts "valid" end
php
if (preg_match('/^-?\d+(?:\.\d+)?%$/', $value)) {
echo "valid";
}java
String pattern = "^-?\\d+(?:\\.\\d+)?%$"; boolean isValid = value.matches(pattern);
Frequently Asked Questions
Related Regex Patterns
Positive Integer
Integers greater than zero (no leading zeros)
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
Hex Color with Alpha
Hex color code with optional alpha channel (3, 4, 6, or 8 digits)