Skip to content

Instantly share code, notes, and snippets.

@anilsingh4580
Forked from HarishChaudhari/passwordRegex.js
Created September 14, 2019 10:10
Show Gist options
  • Save anilsingh4580/c876149396a00db38a27f0611410809c to your computer and use it in GitHub Desktop.
Save anilsingh4580/c876149396a00db38a27f0611410809c to your computer and use it in GitHub Desktop.

Revisions

  1. @HarishChaudhari HarishChaudhari created this gist Aug 1, 2016.
    15 changes: 15 additions & 0 deletions passwordRegex.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    /**
    * Password validation RegEx for JavaScript
    *
    * Passwords must be
    * - At least 8 characters long, max length anything
    * - Include at least 1 lowercase letter
    * - 1 capital letter
    * - 1 number
    * - 1 special character => !@#$%^&*
    *
    * @author Harish Chaudhari <harishchaudhari.com>
    *
    */
    var str = "password"; // your password field's value goes here
    /^(?=.*[\d])(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*])[\w!@#$%^&*]{8,}$/.test(str);