Regex to accept atleast one alphabet one numeric char and one special Character

后端 未结 3 829
夕颜
夕颜 2020-12-12 05:14

I was trying to write a regex that accetps a string that has atleast 1 number 1 alphabet and 1 special character ,

/^[a-zA-Z][a-zA-Z][@#$%^& .. and a bu         


        
相关标签:
3条回答
  • 2020-12-12 05:26

    You can use lookaheads:

    /^(?=.*?[a-z])(?=.*?\d)(?=.*?[...])/i
    

    [...] should hold the special characters you want.

    0 讨论(0)
  • 2020-12-12 05:43
    var item = "1a$";
    item.match(/^[0-9][a-zA-Z][^a-zA-Z0-9\s\t\n]$/)
    

    That should work

    0 讨论(0)
  • 2020-12-12 05:48

    You can use 3 little regex to accomplish that easily (it's more readable) :

    • [0-9]
    • [a-zA-Z]
    • [-_$@...]
    0 讨论(0)
提交回复
热议问题