Tag Archives: Regex

Use RegEx To Test Password Strength In JavaScript


via blog.nraboy: Use RegEx To Test Password Strength In JavaScript.

RegEx is nice because you can accomplish a whole lot with very little.  In this case we are going to check various aspects of a string and see if it meets our requirements, being a strong or medium strength password.

In this example, I’m going to use a mixture of AngularJS and vanilla JavaScript.  Basically, the JavaScript will do all the heavy lifting and the AngularJS code will be responsible for binding it all to the screen.

To show the password strength to the user, we’re going to use a rectangle that contains a color.  We’ll say that a red rectangle holds a weak password, orange medium, and green a strong password.  The HTML behind this would look something like the following:

JavaScript Regex Tutorial: String Methods for Regex


via JavaScript Regex Tutorial: String Methods for Regex.

Regex is used for matching text patterns.

There are 2 ways to use regex in JavaScript:

Normally, you should use string’s regex methods.

Use regex object methods when:

  • you need to construct regex pattern dynamically. ⁖ from user input.
  • you want to use a regex to repeatedly test thousands of different text. (possibly make your code run much faster, because saved regex compile time.)

This page is a tutorial of using string’s regex methods.