Regex for checking if a string is strictly alphanumeric

前端 未结 10 2041
予麋鹿
予麋鹿 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:17

    try this [0-9a-zA-Z]+ for only alpha and num with one char at-least..

    may need modification so test on it

    http://www.regexplanet.com/advanced/java/index.html

    Pattern pattern = Pattern.compile("^[0-9a-zA-Z]+$");
    Matcher matcher = pattern.matcher(phoneNumber);
    if (matcher.matches()) {
    
    }
    

提交回复
热议问题