java正则验证数字、邮箱格式、字符串


用java代码正则验证数字、邮箱格式、字符串的一些工具类方法
        // 判断数字  
        public static boolean isNumberic(String s) {  
            return Pattern.compile("([1-9]+|0)\\.*[0-9]+").matcher(s).matches();  
        }  
      
        // 判断邮箱  
        public static boolean isEmail(String s) {  
            return Pattern.compile("\\w+@{1}\\w+\\.{1}\\w+").matcher(s).matches();  
        }  
      
        // 包含某个字符  
        public static boolean contains(String s, String c) {  
            return Pattern.compile(".*" + c + "+.*").matcher(s).matches();  
        }  
      
        // 以某个字符串开头  
        public static boolean startWith(String s, String c) {  
            return Pattern.compile("^" + c + "\\w*").matcher(s).matches();  
        }  
      
        // 以某个字符串结尾  
        public static boolean endWith(String s, String c) {  
            return Pattern.compile("\\w*" + c + "$").matcher(s).matches();  
        }  

感谢作者:http://supben.iteye.com/blog/1665568

猜你喜欢

转载自zhenxingluo918.iteye.com/blog/2238603
今日推荐