加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

用正则表达式来判断文字是否仅为字母a-zA-Z1-9_的组合.

发布时间:2020-12-14 01:42:15 所属栏目:百科 来源:网络整理
导读:下面是一个简单的模块.用正则表达式来判断文字是否仅为字母a-zA-Z1-(的组合. public Boolean isCharAndNumic(String str) { Boolean is = false; Pattern pt = Pattern.compile("^[0-9a-zA-Z]+$"); Matcher mt = pt.matcher(str); if (mt.matches()) { is =


下面是一个简单的模块.用正则表达式来判断文字是否仅为字母a-zA-Z1-(的组合.


public Boolean isCharAndNumic(String str) {
  Boolean is = false;
  Pattern pt = Pattern.compile("^[0-9a-zA-Z]+$");
  Matcher mt = pt.matcher(str);
  if (mt.matches()) {
    is = true;
    }
  return is;
}


如果还需要加多一个判断下划线的"_".那么很容易修改.

Pattern pt = Pattern.compile("^[0-9a-zA-Z]+$");

在这句话的里面加多"_"在Z的后面就可以啦.

Pattern pt = Pattern.compile("^[0-9a-zA-Z_]+$");

public Boolean isCharNumicAndUnderline(String str) {
  Boolean is = false;
  Pattern pt = Pattern.compile("^[0-9a-zA-Z_]+$");
  Matcher mt = pt.matcher(str);
  if (mt.matches()) {
   is = true;
  }
  return is;
 }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读