I have tried this code. Its not working properly..
String myString = "343DFDFD"; // "FDFS343434"
System.out.println(myString.matches("[A-Za-z0-9]+")); // false coming
note: i want output for above alphanumeric is true
I have tried this code. Its not working properly..
String myString = "343DFDFD"; // "FDFS343434"
System.out.println(myString.matches("[A-Za-z0-9]+")); // false coming
note: i want output for above alphanumeric is true
Modify the regex as:
String myString = "343DFDFD"; // "FDFS343434"
System.out.println(myString.matches("^.*[^a-zA-Z0-9 ].*$")); // false coming
Use it:
public boolean isAlphanumeric(String str) {
for (int i=0; i<str.length(); i++) {
char c = str.charAt(i);
if (!Character.isDigit(c) && !Character.isLetter(c))
return false;
}
return true;
}