package com.mains;
import org.apache.commons.lang.StringUtils;
public class DigistCheck {
private static final String DIGIT_REGEX_FORMAT = "//p{Digit}*";
* 数字
*/
public boolean isDigit(String value)
{
//値Null、True
if(StringUtils.isEmpty(value))
{
return true;
}
return isMatches(value, DIGIT_REGEX_FORMAT);
} // End isDigit
* @param value 検証的値。
* @param regex 正规表达式。
* @return true - 正确, false - 出错。
*/
public boolean isMatches(String value, String regex)
{
//値Null、True
if(StringUtils.isEmpty(value))
{
return true;
}
if(StringUtils.isEmpty(regex)){
return false;
}
return value.matches(regex);
} // End isMatches
public static void main(String[] args) {
String aaa = new String("12345");
DigistCheck tes = new DigistCheck();
if(tes.isDigit(aaa)) {
System.out.println(aaa);}
else {
System.out.println("BBBBBBB");
}
}
}