Regex for Ethereum Address
Regex Pattern
^0x[0-9a-fA-F]{40}$Ethereum address — 0x prefix followed by 40 hex characters
Quick Answer
The regex pattern for ethereum address is `^0x[0-9a-fA-F]{40}$`. Ethereum address — 0x prefix followed by 40 hex characters. This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.
Test Examples
| Input | Result |
|---|---|
| 0x742d35Cc6634C0532925a3b844Bc9e7595f2bD18 | ✓ Matches |
| 0x0000000000000000000000000000000000000000 | ✓ Matches |
| 742d35Cc6634C0532925a3b844Bc9e7595f2bD18 | ✗ No match |
| 0x742d35Cc | ✗ No match |
| 0xGGGGGG | ✗ No match |
Code Examples
javascript
const regex = /^0x[0-9a-fA-F]{40}$/;
const isValid = regex.test(value);python
import re
pattern = r'^0x[0-9a-fA-F]{40}$'
if re.match(pattern, value):
print("valid")ruby
pattern = /^0x[0-9a-fA-F]{40}$/
if value =~ pattern
puts "valid"
endphp
if (preg_match('/^0x[0-9a-fA-F]{40}$/', $value)) {
echo "valid";
}java
String pattern = "^0x[0-9a-fA-F]{40}$";
boolean isValid = value.matches(pattern);Frequently Asked Questions
Related Regex Patterns
Visa Credit Card
Visa card — starts with 4, 13 or 16 digits total
Mastercard Credit Card
Mastercard — 16 digits starting with 51-55 or 2221-2720
American Express Card
Amex — 15 digits starting with 34 or 37
Any Credit Card
Visa, Mastercard, Amex, Discover, Diners
Discover Credit Card
Discover card — starts with 6011 or 65, 16 digits total
Diners Club Credit Card
Diners Club card — starts with 300-305, 36, or 38, 14 digits total