testvalidator.java
来自「这是一个关于J2EE的开源包common里的许多组件的示例应用程序,可以借鉴.」· Java 代码 · 共 59 行
JAVA
59 行
/**
* Title : Base Dict Class
* Description : here Description is the function of class, here maybe multirows
* @author kevin
* @Version 1.0
*/
package validator;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import org.apache.commons.validator.Field;
import org.apache.commons.validator.GenericValidator;
import org.apache.commons.validator.ValidatorUtil;
/**
* Class description goes here.
* @version 1.0 2005-11-9
* @author kevin
*/
public class TestValidator
{ /**
* Checks if the field is required.
*
* @param value The value validation is being performed on.
* @return boolean If the field isn't null and
* has a length greater than zero,
* true is returned.
* Otherwise false.
*/
public static boolean validateRequired(Object bean, Field field) {
String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
return !GenericValidator.isBlankOrNull(value);
}
public static boolean validateInt(Object bean, Field field) {
String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
return GenericValidator.isInt(value);
}
public static void main(String[] s)
{
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
formatter.setLenient(false);
try {
formatter.parse("12/31/2");
} catch(ParseException e) {
e.printStackTrace() ;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?