Javascript Regular Expression For Atleast One Number And One Uppercase Letter
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{
Solution 1:
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).*$/);
Solution 2:
If the desire is to test a string to see if it has a least one digit and at least one uppercase letter in any order and with any other characters allowed too, then this will work:
var str = "abc32Qdef";
var re = /[A-Z].*\d|\d.*[A-Z]/;
var good = re.test(str);
Working demo with a bunch of test cases here: http://jsfiddle.net/jfriend00/gYEmC/
Solution 3:
Like below:
/(\d.*[A-Z])|([A-Z].*\d)/
To test a string matched or not:
var str = "abc32dQef";
var is_matched = /(\d.*[A-Z])|([A-Z].*\d)/.test(str);
Post a Comment for "Javascript Regular Expression For Atleast One Number And One Uppercase Letter"