[Javascript] Thoughts on applying Regex

You don't really need to apply a really complex regex for one validation, instead you can combine multi regex together to fulfilll the task.

const regex = /^[\w!@$%^&*-+]{8,}/.test(password)
    && /[a-z]/.test(password)
    && /[A-Z]/.test(password)    
    && /[\d]/.test(password)    
    && /[!@$%^&&\-]/.test(password)

 

posted @ 2024-07-08 14:57  Zhentiw  阅读(4)  评论(0编辑  收藏  举报