Skip to content

Instantly share code, notes, and snippets.

@mayowDev
Created December 2, 2020 07:52
Show Gist options
  • Save mayowDev/95270b2a697fa03889a1ae74539fa35d to your computer and use it in GitHub Desktop.
Save mayowDev/95270b2a697fa03889a1ae74539fa35d to your computer and use it in GitHub Desktop.

Revisions

  1. mayowDev created this gist Dec 2, 2020.
    24 changes: 24 additions & 0 deletions Regex password & email
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    > Your password must be at least 8 characters long and include at least one number and one of the following symbols !@#$%^&()*

    const isEmailValid = (mail) => {
    if (mail) {
    return /^\S+@\S+\.\S+$/.test(mail) === true
    }
    return true
    }

    const isPasswordValid = (pass) => {
    if (pass) {
    return pass.length > 7 && /^(?=.*\d)(?=.*[a-z])(?=.*[!@#$%^&()*])(?=.*[a-z]).{8,}$/i.test(pass) === true
    }
    return true
    }


    const checkPassword = (password) => {
    if (password.length >= 1) {
    const isValid = isPasswordValid(password)
    console.log('isValid = ', isValid, password)
    setPasswordValid(isValid)
    }
    }