Python re demo
2019-07-17 本文已影响0人
JaedenKil
Verify whether user has inputted valid username and qq number.
Require:
- Username must only contain number, letter and underline, length between 6 to 20.
- QQ number length between 5 to 12, first number is not zero.
import re
def main():
username = input("Input username")
qq = input("Input qq number")
m1 = re.match(r'^[a-zA-Z1-9_]{6,20}$', username)
m2 = re.match(r'^[1-9]\d{4,11}$', qq)
if not m1:
print("Invalid username")
if not m2:
print("Invalid qq number")
if m1 and m2:
print("Valid username and qq number")
if __name__ == "__main__":
main()