Created
November 17, 2016 16:13
-
-
Save Highstaker/55cbe009552bc5bd3061f912d93a9f02 to your computer and use it in GitHub Desktop.
Simple IP validation with Python and regex
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
import re | |
number_pattern = r"(([1-9]?[0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5]))" | |
IP_validator = re.compile(r'^{0}(\.{0}){1}$'.format(number_pattern, "{3}")) | |
def is_valid_IP(strng): | |
return bool(IP_validator.match(strng)) | |
is_valid_IP("12.34.56.708") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment