Last active
August 29, 2015 14:13
-
-
Save i07/2df72a66cf56dd3ad146 to your computer and use it in GitHub Desktop.
Validate an IP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function validate_ip(ipaddr) | |
{ | |
if (/\b(?:(?: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]?)\b/.test(ipaddr)) | |
return true; | |
return false; | |
} | |
usage: | |
<script> | |
if ( validate_ip("192.168.10.10") ) { | |
/* ip is valid */ | |
} else { | |
/* ip is not valid */ | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment