Ip Address Ipv4 Javascript
ip address ipv4 javascript for production applications
Pattern Views
29,597
↗ 12.5%Last 30 days
Community Rating
⭐
94%
357 likes
Regular Expression
/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/
Explanation
This regex pattern validates ip address ipv4 javascript. Commonly used by developers for input validation and form checking.
Code Examples
JavaScript Example
javascript
// ip address ipv4 javascript - JavaScript
const regex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
function validate(input) {
if (!input || typeof input !== 'string') return false;
return regex.test(input.trim());
}
// Usage examples
console.log(validate('192.168.1.1')); // true
console.log(validate('256.256.256.256')); // falsePython Example
python
# ip address ipv4 javascript - Python
import re
pattern = r"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
regex = re.compile(pattern)
def validate(input_str):
if not input_str or not isinstance(input_str, str):
return False
return bool(regex.match(input_str.strip()))
# Usage examples
print(validate('192.168.1.1')) # True
print(validate('256.256.256.256')) # FalsePHP Example
php
<?php
// ip address ipv4 javascript - PHP
function validate($input) {
if (!is_string($input) || empty(trim($input))) {
return false;
}
$pattern = '/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/';
return preg_match($pattern, trim($input)) === 1;
}
// Usage examples
var_dump(validate('192.168.1.1')); // bool(true)
var_dump(validate('256.256.256.256')); // bool(false)
?>Test Cases
✓ Should Match
192.168.1.1
10.0.0.1
✗ Should NOT Match
256.256.256.256
Performance
Speed
fast
Memory
low