views:

52

answers:

2

I want to check password strength of password entered by user in Asp.Net page. I have comeup with a javascript regular expression to do it.
But I am not sure How to match string using regular expression. I have write this code, but its not working.

I think there is an error in line

   if (true==checkspace.exec(password))
   alert("spaces are not allowed");
+2  A: 

Take a look at the JavaScript Regular Expression object methods

it looks like you want .test(), as you expect a boolean to be returned, depending on if the pattern is found in the string

regularExpression.test("my string to test");
Russ Cam
How to check white spaces.
vaibhav
`/\s/g.test("my string to test");` will return true if the string contains a whitespace
Russ Cam
A: 

For example if you want to test that a password is at least 6 characters long and contains at least one uppercase and one lowercase letter and at least one digit you could use this:

var passwordRegex = /^.*(?=.{6,})(?=.*[a-z])(?=.*[A-Z])(?=.*[\d\W]).*$/;
var password = 'adg6htyA';
var isPasswordStrong = passwordRegex.test(password);
alert(isPasswordStrong); // shows true
Darin Dimitrov