Verifique se uma string é alfanumérica
if (string.match(/^[0-9A-Za-z]+$/) === null) {
//is not alphanumeric
}else{
//it is alphanumeric
}
Grieving Gharial
if (string.match(/^[0-9A-Za-z]+$/) === null) {
//is not alphanumeric
}else{
//it is alphanumeric
}
javaCopypublic class CheckCharAlpha {
public static void main(String[] args) {
boolean letterOrDigit = isAlphaNumeric('k');
System.out.println(letterOrDigit);
}
public static boolean isAlphaNumeric(char char1) {
return (char1 >= 'a' && char1 <= 'z') || (char1 >= 'A' && char1 <= 'Z') || (char1 >= '0' && char1 <= '9');
}
}
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]+"));
}
}