代码如下:
#encoding=utf-8#——————————————————————————-# name: 模块1# purpose:## author: administrator## created: 10-06-2014# copyright: (c) administrator 2014# licence: #——————————————————————————-import redef checklen(pwd): return len(pwd)>=8def checkcontainupper(pwd): pattern = re.compile(‘[a-z]+’) match = pattern.findall(pwd) if match: return true else: return falsedef checkcontainnum(pwd): pattern = re.compile(‘[0-9]+’) match = pattern.findall(pwd) if match: return true else: return falsedef checkcontainlower(pwd): pattern = re.compile(‘[a-z]+’) match = pattern.findall(pwd) if match: return true else: return falsedef checksymbol(pwd): pattern = re.compile(‘([^a-z0-9a-z])+’) match = pattern.findall(pwd) if match: return true else: return falsedef checkpassword(pwd): #判断密码长度是否合法 lenok=checklen(pwd) #判断是否包含大写字母 upperok=checkcontainupper(pwd) #判断是否包含小写字母 lowerok=checkcontainlower(pwd) #判断是否包含数字 numok=checkcontainnum(pwd) #判断是否包含符号 symbolok=checksymbol(pwd) print(lenok) print(upperok) print(lowerok) print(numok) print(symbolok) return (lenok and upperok and lowerok and numok and symbolok)
def main(): if checkpassword(‘helloworld#123’): print(‘检测通过’) else: print(‘检测未通过’)
if __name__ == ‘__main__’: main()
平时用正则不多,不知道怎么写一个正则满足要求,用了比较笨的办法,谁知道一句正则检验的请赐教!