regular expression for password with few rules

前端 未结 3 1727
迷失自我
迷失自我 2021-01-16 05:54

I want a function checkPassword function, which should check if the password parameter adheres to the following rules:

  1. Must be longer than 6 characters
3条回答
  •  温柔的废话
    2021-01-16 06:10

    You can use the following regex and get the content of the capturing group to check if your string is valid:

    .*\d{3}.*|^([\w\+$#/\\]{6,})$
    

    Working demo

    Using \w allows A-Za-z0-9_ if you don't want underscore on your regex you have to replace \w by A-Za-z0-9

    For the following examples:

    pass12p            --> Pass
    pass125p           --> Won't pass
    asdfasf12asdf34    --> Pass
    asdfasf12345asdf34 --> Won't pass
    

    Match information is:

    MATCH 1
    1.  `pass12p`
    MATCH 2
    1.  `asdfasf12asdf34`
    

提交回复
热议问题