IP地址 密码复杂度 正则
import socket def is_valid(ip): """Returns true if the given string is a well-formed IP address. Supports IPv4 and IPv6. """ if len(ip.split(".")) != 4: return False if not ip or '\x00' in ip: # getaddrinfo resolves empty strings to localhost, and truncates # on zero bytes. return False try: res = socket.getaddrinfo(ip, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_NUMERICHOST) return bool(res) except socket.gaierror as e: if e.args[0] == socket.EAI_NONAME: return False return True
必须包含 数字、字母和特殊符号,8-30位长度
(?=.*\d)(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{8,30}
(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{8,30}