Regex for checking if a string is strictly alphanumeric

前端 未结 10 2068
予麋鹿
予麋鹿 2020-12-01 12:02

How can I check if a string contains only numbers and alphabets ie. is alphanumeric?

10条回答
  •  甜味超标
    2020-12-01 12:29

    Pattern pattern = Pattern.compile("^[a-zA-Z0-9]*$");
    Matcher matcher = pattern.matcher("Teststring123");
    if(matcher.matches()) {
         // yay! alphanumeric!
    }
    

提交回复
热议问题