Python re demo

作者: JaedenKil | 来源:发表于2019-07-17 19:06 被阅读0次

    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()
    

    相关文章

      网友评论

        本文标题:Python re demo

        本文链接:https://www.haomeiwen.com/subject/uxsclctx.html