i need to get the value which only Alphanumeric and it can be of anything which comes under this
1. asd7989 - true
2. 7978dfd - true
3. auo789dd - true
4. 9799 - false
5.any special characters - false
i tried with the following but it does not give expected result
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.struts.action.ActionMessage;
public class Test {
public static void main(String[] args) {
Pattern pattern = Pattern.compile("^[0-9a-zA-Z]+$");
Matcher matcher = pattern.matcher("465123");
if(matcher.matches()) {
System.out.println("match");
}else{
System.out.println("not match");
}
}
}
the result should actually be not match but i get as match
charof the String and checks if it's in the range you want: