what would be the regular expression to check if a given string contains atleast one number and one uppercase letter?
Thanks in advance
I am doing like this
function validate_pass{
var var_password = document.getElementById("npassword").value;
else if (!(/^(?=.*\d)(?=.*[A-Z]).+$/).test(var_password))){
msg = "Password should contain atleast.";
showErrorMsgPassword(msg);
$('#npassword').val('');
$('#cpassword').val('');
return false;
}
else return true;
It’s been a while since I’ve done this, and I’m fairly certain there is a more efficient way than this. You will need to use positive lookaheads, but there should be a way to remove the wildcards from within them:
This regex (
/^(?=.*[A-Z])(?=.*\d).*$/) will return the entire password if it matches the criteria.('a3sdasFf').match(/^(?=.*[A-Z])(?=.*\d).*$/);