zoukankan      html  css  js  c++  java
  • JAVA正则表达式验证英文字母、汉字和数字!!!

    java用正则表达式判断字符串中是否仅包含英文字母、数字和汉字

    public static boolean isLetterDigitOrChinese(String str) {
      String regex = "^[a-z0-9A-Zu4e00-u9fa5]+$";
      return str.matches(regex);
     }

     java代码输入框验证(本公司封装框架)

    /**
         * 代码集名称和描述校验
         */
        @PageEvent("specialValue")
        @NoRequiredValidate
        public void specialValue() throws Exception {
            String t2Value = this.getPageElement("t2").getValue();
            String area2Value = this.getPageElement("area2").getValue();
            if (t2Value != null && !"".equals(t2Value)) {
                String regex = "^[A-Za-z0-9u4e00-u9fa5]+$";
                if (t2Value.matches(regex)) {
                    this.getPageElement("t2").setValue(t2Value);
                } else {
                    this.setMainMessage("代码集名称只能输入汉字、字母或阿拉伯数字");
                    this.getPageElement("t2").setValue("");
                }
            }
            if (area2Value != null && !"".equals(area2Value)) {
                String regex = "^[A-Za-z0-9u4e00-u9fa5]+$";
                if (area2Value.matches(regex)) {
                    this.getPageElement("area2").setValue(area2Value);
                } else {
                    this.setMainMessage("代码集名称只能输入汉字、字母或阿拉伯数字");
                    this.getPageElement("area2").setValue("");
                }
            }
        }

     js 正则表达式 以字母开头,英文、数字、下划线和减号 6-20位

    function checkWechatAccount(v){
       var reg = /^[a-zA-Z]([-_a-zA-Z0-9]{6,20})$/;
        if(!reg.test(v)){
            document.getElementById("wechatAccount").value="";
            $("#wechatAccountError").show();
    
        }else{
            $("#wechatAccountError").hide();
        }
    }

     限制长度1-20位

    public class Test {
    
    
        public static boolean isLetterDigitOrChinese(String str) {
            //String regex = "^[-_.·a-z0-9A-Zu4e00-u9fa5]+$";
            String regex = "^[-_.·a-z0-9A-Zu4e00-u9fa5]{1,20}$";
            return str.matches(regex);
        }
    
    
        public static void main(String[] args) {
            String str1 = "张三";
            String str2 = "张三·李四";
            String str3 = "-_-Aa123.中国";
            String str4 = "-_-Aa123.中国#";
            String str5 = "-_-Aa123.中国/";
            String reuslt = str3;
            System.out.println(isLetterDigitOrChinese(reuslt));
    
        }
    }

    转载于:https://blog.csdn.net/fengyeqing5/article/details/84920998

  • 相关阅读:
    线程的终止pthread_exit和返回为什么终止的原因
    临界区互斥使用之使用自旋锁
    临界区的同步操作-------------使用信号量 实现
    常用解压操作
    group compare vs pair compare
    两个总体的参数关系
    纳伪|去真
    Ho|H1|p-value|p值与U值|单侧检验
    统计分布近似转化
    样本均值的标准误差|样本均值的标准差|总体标准差|样本标准差|简单随机抽样|样本均值估计|样本方差估计|
  • 原文地址:https://www.cnblogs.com/it-deepinmind/p/13691261.html
Copyright © 2011-2022 走看看