If you want to prevent leading or trailing spaces, just remove the last \s
. To set a minimum length for the password, change your +
quantifier to {n,}
, where n is the minimum length.
For example, the following pattern matches any sequence of 5 or more alphanumeric characters that contains at least one letter, and at least one number:
/^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]{5,})$/