I wouldn't recommend trying to do this whole check in a single regular expression because it just over complicates it. Do each condition individually.
Has at least one letter:
var has_letters = (/[a-zA-Z]/).test(password);
Has at least one number:
var has_numbers = (/[0-9]/).test(password);
Has between 3 and 30 characters (inclusive):
var has_length = 3 <= password.length && password.length <= 30;
This can all be wrapped up into a function:
function is_password_valid(password) {
var has_letters = (/[a-zA-Z]/).test(password);
var has_numbers = (/[0-9]/).test(password);
var has_length = 3 <= password.length && password.length <= 30;
return has_letters && has_numbers && has_length;
}
Or if you prefer something more dense:
function is_password_valid(password) {
return ((/[a-zA-Z]/).test(password)
&& (/[0-9]/).test(password)
&& password.length >= 3
&& password.length <= 30);
}
.length. For #1 and #2, just use two regular expressions to check that the value contains a alpha and numeric character each. For example:var value = "YOUR INPUT", alpha = /[A-Za-z]/, numeric = /[0-9]/; if (value.length < 3 || value.length > 30 || !alpha.test(value) || !numeric.test(value)) { /* INVALID */ }. It's a lot easier to read/understand/maintain, in my opinion