Skip to main content

Posts

Showing posts with the label Password Strength Validation using Regular Expression

Password Strength Validation using Regular Expression in AngularJs

Hello everyone, I am going to share the code sample for validate the strength of Password field using the regular expressions. The regular expression is two type one is strong regular expression and other is medium regular expression as given below. Go and click to Live demo test example code with plunker . The strong regular expression var strongRegularExp = new RegExp( "^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[! @ #\$%\^&\*])(?=.{8,})" ); The medium regular expression var mediumRegularExp = new RegExp( "^(((?=.*[a-z])(?=.*[A-Z]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*[0-9])))(?=.{6,})" ); If password strength is strong then display green color meter and if medium then display orange color meter other-wise red color meter. The JavaScript code sample as given below .. var app = angular.module( "StrengthValidationApp" , []);     app.controller( "StrengthValidationCtrl" , function ($scope) {     ...