I need to validate passwords in Ruby, with the requirement that they must contain at least one letter (/[a-z]{1,}/) and one number (/\d{1,}/). But these can occur in any order within the string. Can I do this in a single regexp?
'aa' => should not match
'99' => should not match
'a9' => should match
'9a' => should match
These don’t work:
'9a' =~ /[a-b]{1,}\d{1,}/ <= no match
'a' =~ /[a-b]{1,}|\d{1,}/ <= match
Unfortunately I can’t find something like a & (AND) operator corresponding to the | (OR) operator Is there a way to do this?
You can do it like this: