Copy codeThe Code is as follows:
# Encoding = UTF-8
#-------------------------------------------------------------------------------
# Name: Module 1
# Purpose:
#
# Author: Administrator
#
# Created: 10-06-2014
# Copyright: (c) Administrator 2014
# Licence: <your licence>
#-------------------------------------------------------------------------------
Import re
Def checklen (pwd ):
Return len (pwd)> = 8
Def checkContainUpper (pwd ):
Pattern = re. compile ('[A-Z] + ')
Match = pattern. findall (pwd)
If match:
Return True
Else:
Return False
Def checkContainNum (pwd ):
Pattern = re. compile ('[0-9] + ')
Match = pattern. findall (pwd)
If match:
Return True
Else:
Return False
Def checkContainLower (pwd ):
Pattern = re. compile ('[a-z] + ')
Match = pattern. findall (pwd)
If match:
Return True
Else:
Return False
Def checkSymbol (pwd ):
Pattern = re. compile ('([^ a-z0-9A-Z]) + ')
Match = pattern. findall (pwd)
If match:
Return True
Else:
Return False
Def checkPassword (pwd ):
# Determine whether the password length is valid
LenOK = checklen (pwd)
# Determine whether an uppercase letter is contained
UpperOK = checkContainUpper (pwd)
# Determine whether a lowercase letter is contained
LowerOK = checkContainLower (pwd)
# Determine whether a number is included
NumOK = checkContainNum (pwd)
# Determine whether a symbol is contained
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 ('detected pass ')
Else:
Print ('failed detection ')
If _ name _ = '_ main __':
Main ()
There are not many regular expressions at ordinary times. I don't know how to write a regular expression to meet the requirements. I am using a stupid method. Please kindly advise if I have a regular expression test!