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();
            }
  • 相关阅读:
    mysql删选某列重复值
    apache伪静态
    nginx的伪静态
    如何对数据库进行优化
    ci的优缺点
    memcache状态说明
    sql中扩展插入语法
    若给个 个人收款的二维码,如何测试?
    安装自动化测试工具selenium
    PHP 线上项目 无法操作
  • 原文地址:https://www.cnblogs.com/a8047/p/14159421.html
Copyright © 2011-2022 走看看