My requirement is to match a regex with at least one alphabet[a-z], at least one number[0-9] and at least any symbols. For example: (~`!@#$%^&*()-_ ={}[]|;:"<>,./?)
The valid ones should be:
- blog@123
- 12#code
- $$455hi
The invalid ones are:
- blog123
- 1223
- blog
CodePudding user response:
Use lookaheads to be sure the string includes the required characters:
^(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[~`!@#$%^&*()_ ={}[\]|;:"<>,.\/?-]).*$
Also don't forget to escape ]
and /
.