java.util.regex.*; class AlphanumericExample { public static void main(String...s) { String s1="adA12", s2="jh@l"; System.out.println(s1.matches("[a-zA-Z0-9]+")); System.out.println(s2.matches("[a-zA-Z0-9]+")); } }