mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2024-11-20 10:39:59 +01:00
33 lines
633 B
Python
33 lines
633 B
Python
import re
|
|
import socket
|
|
|
|
|
|
# Function to validate domain name.
|
|
def isValidDomain(str):
|
|
# Regex to check valid
|
|
# domain name.
|
|
regex = "^((?!-)[A-Za-z0-9-]{1,63}(?<!-)\\.)+[A-Za-z]{2,6}"
|
|
# Compile the ReGex
|
|
p = re.compile(regex)
|
|
|
|
# If the string is empty
|
|
# return false
|
|
if str == None:
|
|
return False
|
|
|
|
# Return if the string
|
|
# matched the ReGex
|
|
if re.search(p, str):
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
|
|
# Function to validate IP address
|
|
def isvalidIPAddress(str):
|
|
try:
|
|
socket.inet_aton(str)
|
|
return True
|
|
except socket.error:
|
|
return False
|