I need a regex which will satisfy both conditions.
It should give me true only when a String contains both A-Z and 0-9.
Here’s what I’ve tried:
if PNo[0].matches("^[A-Z0-9]+$")
It does not work.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I suspect that the regex below is slowed down by the look-around, but it should work regardless:
The regex asserts that there is an uppercase alphabetical character
(?=.*[A-Z])somewhere in the string, and asserts that there is a digit(?=.*[0-9])somewhere in the string, and then it checks whether everything is either alphabetical character or digit.