0

i'm working on a student porject of Hospital system.

I'm facing an issue, when it comes to regular expressions, I need to check if one of my string contains at least one [a-z], [A-Z] and a [0-9]. I've tried this :

test = Pattern.matches("[a-z & A-Z & 0-9]{1}",String) ;

I don't see my mistake since it's has been a long time with my last regular expressions...

A little help would be appreciated. Thanks !

  • This page can be helpful if you want to accomplish that https://stackoverflow.com/questions/19605150/regex-for-password-must-contain-at-least-eight-characters-at-least-one-number-a – The fourth bird Jan 22 '20 at 16:09
  • You can call `Pattern.matches()` three times. Once for each requirement. – MonkeyZeus Jan 22 '20 at 16:10
  • Your other choice is a positive lookahead for each requirement such as `(?=.*[a-z])(?=.*[A-Z])(?=.*\d)` – MonkeyZeus Jan 22 '20 at 16:12
  • here the official [documentation](https://docs.oracle.com/en/java/javase/13/docs/api/java.base/java/util/regex/Pattern.html) Notes: `&` is not needed inside `[]` (`[a-zA-Z0-9]` would match one of the given character (in the ranges)); `{1}` is not needed, kind of the default – user85421 Jan 22 '20 at 16:18
  • @user85421 OP wants one form each range so in English "One uppercase, one lowercase, and one digit is required in any order." – MonkeyZeus Jan 22 '20 at 16:22
  • @Monkey I know (despite question not very precise on that) , I am just correcting the posted regex (see "Notes:..." in my comment), never said it would do the job ... and is `&` needed, or `{1}` ? – user85421 Jan 22 '20 at 16:23

0 Answers0