gpt4 book ai didi

java - 检查字母数字输入和间距

转载 作者:行者123 更新时间:2023-12-02 04:06:04 26 4
gpt4 key购买 nike

我目前正在使用一种工作正常的方法检查字母数字输入。但我怎样才能检查间距呢?如如果输入有数字、字母和/或空格,我想返回 true。

public static boolean isAlphaNumeric(String input){
if(input.matches("[A-Za-z0-9]+")){
return true;
}
else {
return false;
}
}

最佳答案

尝试下面的代码:

public static boolean isAlphaNumeric(String target){
String pattern= "^[a-zA-Z0-9 ]*$";
return target !=null && target.matches(pattern);
}

关于java - 检查字母数字输入和间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34253698/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com