1

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");
1
  • How to check for white spaces. Commented Oct 31, 2009 at 13:37

2 Answers 2

2

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");
Sign up to request clarification or add additional context in comments.

1 Comment

/\s/g.test("my string to test"); will return true if the string contains a whitespace
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.