zoukankan      html  css  js  c++  java
  • 常用的正则表达式

    "^[0-9]*[1-9][0-9]*$"  //正整数   
    "^((-\d+)|(0+))$"  //非正整数(负整数 + 0)   
    "^-[0-9]*[1-9][0-9]*$"  //负整数   
    "^-?\d+$"    //整数   
    "^\d+(\.\d+)?$"  //非负浮点数(正浮点数 + 0)   
    "^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$"    
    //正浮点数   
    "^((-\d+(\.\d+)?)|(0+(\.0+)?))$"  //非正浮点数(负浮点数 + 0)   
    "^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$"    
    //负浮点数   
    "^(-?\d+)(\.\d+)?$"  //浮点数   
    "^[A-Za-z]+$"  //由26个英文字母组成的字符串   
    "^[A-Z]+$"  //由26个英文字母的大写组成的字符串   
    "^[a-z]+$"  //由26个英文字母的小写组成的字符串   
    "^[A-Za-z0-9]+$"  //由数字和26个英文字母组成的字符串   
    "^\w+$"  //由数字、26个英文字母或者下划线组成的字符串   
    "^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$"    //email地址   
    "^[a-zA-z]+://(\w+(-\w+)*)(\.(\w+(-\w+)*))*(\?\S*)?$"  //url   
    "^[A-Za-z0-9_]*$"s

    例子:

    判断字母和数字

        public boolean isAllowed(String str)
        {
            if(str.length() >= 6 && str.length() <= 12 ){
                Pattern pattern = Pattern.compile("^[A-Za-z0-9]+$");
                return pattern.matcher(str).matches();
            }
            else return false;
        }

    判断整数

    public boolean isNumber(String str) {
                Pattern pattern = Pattern.compile("^[-\+]?[\d]*$");
                return pattern.matcher(str).matches();
            }
  • 相关阅读:
    点击图片等比缩放
    C# 使用 NPOI 库读写 Excel 文件
    vue url生产二维码
    centos Linux 同步Windows 时间
    centos 搭建 docker sentry
    centos 安装 pip
    webpack 提升90%的构建速度 HardSourceWebpackPlugin
    webpack 原生分析
    webpack 分析
    nodejs——js 实现webSocket 兼容移动端
  • 原文地址:https://www.cnblogs.com/a8047/p/14159421.html
Copyright © 2011-2022 走看看