/**
* 检查日期格式
* @param date
* @return
*/
public static boolean checkDate(String date) {
String eL = "^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|
(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?
((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|
(1[0-9])|(2[0-8]))))))(\\s(((0?[0-9])|([1][0-9])|([2][0-3]))\\:([0-5]?[0-9])((\\s)|(\\:([0-5]?[0-9])))))?$";
Pattern p = Pattern.compile(eL);
Matcher m = p.matcher(date);
boolean b = m.matches();
return b;
}
/**
* 检查整数
* @param num
* @param type "0+":非负整数 "+":正整数 "-0":非正整数 "-":负整数 "":整数
* @return
*/
public static boolean checkNumber(String num,String type){
String eL = "";
if(type.equals("0+"))eL = "^\\d+$";//非负整数
else if(type.equals("+"))eL = "^\\d*[1-9]\\d*$";//正整数
else if(type.equals("-0"))eL = "^((-\\d+)|(0+))$";//非正整数
else if(type.equals("-"))eL = "^-\\d*[1-9]\\d*$";//负整数
else eL = "^-?\\d+$";//整数
Pattern p = Pattern.compile(eL);
Matcher m = p.matcher(num);
boolean b = m.matches();
return b;
}
/**
* 检查浮点数
* @param num
* @param type "0+":非负浮点数 "+":正浮点数 "-0":非正浮点数 "-":负浮点数 "":浮点数
* @return
*/
public static boolean checkFloat(String num,String type){
String eL = "";
if(type.equals("0+"))eL = "^\\d+(\\.\\d+)?$";//非负浮点数
else if(type.equals("+"))eL = "^((\\d+\\.\\d*[1-9]\\d*)|(\\d*[1-9]\\d*\\.\\d+)|(\\d*[1-9]\\d*))$";//正浮点数
else if(type.equals("-0"))eL = "^((-\\d+(\\.\\d+)?)|(0+(\\.0+)?))$";//非正浮点数
else if(type.equals("-"))eL = "^(-((\\d+\\.\\d*[1-9]\\d*)|(\\d*[1-9]\\d*\\.\\d+)|(\\d*[1-9]\\d*)))$";//负浮点数
else eL = "^(-?\\d+)(\\.\\d+)?$";//浮点数
Pattern p = Pattern.compile(eL);
Matcher m = p.matcher(num);
boolean b = m.matches();
return b;
}
相关推荐
匹配中文字符的正则表达式: [u4e00-u9fa5] 评注:匹配中文还真是个头疼的事,有了这个表达式就好办了 匹配双字节字符(包括汉字在内):[^x00-xff] 评注:可以用来计算字符串的长度(一个双字节字符长度计2...
即使有经验的用户也经常会遇到性能不佳、误报、漏报等让人挠头的错误,本书对于如何使用正则表达式来解决一些常见的问题给出了按部就班的解决方案,其中包括c#、Java、JavaScript、Perl、PHP、Python、Ruby和VB...
即使有经验的用户也经常会遇到性能不佳、误报、漏报等让人挠头的错误,本书对于如何使用正则表达式来解决一些常见的问题给出了按部就班的解决方案,其中包括c#、Java、JavaScript、Perl、PHP、Python、Ruby和VB...
这样说来,正则表达式/java/就和 所有包含子串 "java" 的字符串相匹配.虽然正则表达式中的其它字符不是按照字面意思进行匹配的,但它们都具有特殊的意义.正则表达式 /s$/ 包含两个字符. 第一个特殊字符 "s" 是按照...
//java正则表达式数字验证 public boolean isNumber(String str) { java.util.regex.Pattern pattern=java.util.regex.Pattern.compile("[0-9]+(.[0-9]+)?"); java.util.regex.Matcher match=pattern.matcher...
* Summary of regular-expression constructs 正则表达式结构简介: * Construct Matches * Characters 字符: * x The character x x 字符 x * \\ The ...
您可能感兴趣的文章:解析使用js判断只能输入数字、字母等验证的方法(总结)js判断输入是否为正整数、浮点数等数字的函数代码javaScript 判断字符串是否为数字的简单方法javascript使用isNaN()函数判断变量是否为数字...
19.正则表达式对象:(专门用于查找和验证) reg.test(‘要验证的完整字符串’)匹配返回true,否则返回false 强调:如果正则表达式使用了^和$,必须完整匹配才行。反之则部分匹配 20.Date对象:(计算方法:先get,...
{3.4}正则表达式}{71}{section.3.4} {3.5}StringBuffer}{75}{section.3.5} {3.6}StringBuilder}{76}{section.3.6} {3.7}StringBuilder与StringBuffer的缺点}{76}{section.3.7} {3.8}内部类}{77}{section.3.8} ...
PHP支持整数、浮点数、字符串、数组和对象。变量类型通常不由程序员决定而由PHP运行过程决定(真是好的解脱!)。但是类型也可以被函数cast或者settype()明确的设定。 数值 数值类型可以是整数或是浮点数。你可以...