本文整理汇总了Java中org.apache.commons.validator.GenericValidator.matchRegexp方法的典型用法代码示例。如果您正苦于以下问题:Java GenericValidator.matchRegexp方法的具体用法?Java GenericValidator.matchRegexp怎么用?Java GenericValidator.matchRegexp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.validator.GenericValidator
的用法示例。
在下文中一共展示了GenericValidator.matchRegexp方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateMask
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
/**
* Checks if the field matches the regular expression in the field's mask attribute.
*
* @param bean The bean validation is being performed on.
* @param va The <code>ValidatorAction</code> that is currently being
* performed.
* @param field The <code>Field</code> object associated with the current
* field being validated.
* @param errors The <code>ActionMessages</code> object to add errors to if
* any validation errors occur.
* @param validator The <code>Validator</code> instance, used to access
* other field values.
* @param request Current request object.
* @return true if field matches mask, false otherwise.
*/
public static boolean validateMask(Object bean,
ValidatorAction va, Field field,
ActionMessages errors,
Validator validator,
HttpServletRequest request) {
String mask = field.getVarValue("mask");
String value = null;
if (isString(bean)) {
value = (String) bean;
} else {
value = ValidatorUtils.getValueAsString(bean, field.getProperty());
}
try {
if (!GenericValidator.isBlankOrNull(value)
&& !GenericValidator.matchRegexp(value, mask)) {
errors.add(
field.getKey(),
Resources.getActionMessage(validator, request, va, field));
return false;
} else {
return true;
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return true;
}
示例2: validateManagedRepository
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
/**
* validate cronExpression and location format
*
* @param managedRepository
* @since 1.4-M2
*/
@Override
public void validateManagedRepository( ManagedRepository managedRepository )
throws RepositoryAdminException
{
String cronExpression = managedRepository.getCronExpression();
// FIXME : olamy can be empty to avoid scheduled scan ?
if ( StringUtils.isNotBlank( cronExpression ) )
{
CronExpressionValidator validator = new CronExpressionValidator();
if ( !validator.validate( cronExpression ) )
{
throw new RepositoryAdminException( "Invalid cron expression.", "cronExpression" );
}
}
else
{
throw new RepositoryAdminException( "Cron expression cannot be empty." );
}
String repoLocation = removeExpressions( managedRepository.getLocation() );
if ( !GenericValidator.matchRegexp( repoLocation,
ManagedRepositoryAdmin.REPOSITORY_LOCATION_VALID_EXPRESSION ) )
{
throw new RepositoryAdminException(
"Invalid repository location. Directory must only contain alphanumeric characters, equals(=), question-marks(?), "
+ "exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-).",
"location" );
}
}
示例3: validateMask
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
/**
* Checks if the field matches the regular expression in the field's mask
* attribute.
*
* @param bean The bean validation is being performed on.
* @param va The <code>ValidatorAction</code> that is currently
* being performed.
* @param field The <code>Field</code> object associated with the
* current field being validated.
* @param errors The <code>ActionMessages</code> object to add errors
* to if any validation errors occur.
* @param validator The <code>Validator</code> instance, used to access
* other field values.
* @param request Current request object.
* @return true if field matches mask, false otherwise.
*/
public static boolean validateMask(Object bean, ValidatorAction va,
Field field, ActionMessages errors, Validator validator,
HttpServletRequest request) {
String value = null;
value = evaluateBean(bean, field);
try {
String mask =
Resources.getVarValue("mask", field, validator, request, true);
if (value != null && value.length()>0
&& !GenericValidator.matchRegexp(value, mask)) {
errors.add(field.getKey(),
Resources.getActionMessage(validator, request, va, field));
return false;
} else {
return true;
}
} catch (Exception e) {
processFailure(errors, field, "mask", e);
return false;
}
}
示例4: validateMask
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
/**
* Fails if a field's value does not match the given mask.
*/
public static boolean validateMask(CheckResultSourceInterface source, String propertyName, int levelOnFail,
List<CheckResultInterface> remarks, String mask)
{
final String VALIDATOR_NAME = "matches"; //$NON-NLS-1$
String value = null;
value = ValidatorUtils.getValueAsString(source, propertyName);
try
{
if (null == mask)
{
addGeneralRemark(source, propertyName, VALIDATOR_NAME, remarks,
"errors.missingVar", CheckResultInterface.TYPE_RESULT_ERROR); //$NON-NLS-1$
return false;
}
if (StringUtils.isNotBlank(value) && !GenericValidator.matchRegexp(value, mask))
{
addFailureRemark(source, propertyName, VALIDATOR_NAME, remarks, levelOnFail);
return false;
} else
{
return true;
}
} catch (Exception e)
{
addExceptionRemark(source, propertyName, VALIDATOR_NAME, remarks, e);
return false;
}
}
示例5: validateMask
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
/**
* Fails if a field's value does not match the given mask.
*/
public static boolean validateMask( CheckResultSourceInterface source, String propertyName, int levelOnFail,
List<CheckResultInterface> remarks, String mask ) {
final String VALIDATOR_NAME = "matches";
String value = null;
value = ValidatorUtils.getValueAsString( source, propertyName );
try {
if ( null == mask ) {
addGeneralRemark(
source, propertyName, VALIDATOR_NAME, remarks, "errors.missingVar",
CheckResultInterface.TYPE_RESULT_ERROR );
return false;
}
if ( StringUtils.isNotBlank( value ) && !GenericValidator.matchRegexp( value, mask ) ) {
addFailureRemark( source, propertyName, VALIDATOR_NAME, remarks, levelOnFail );
return false;
} else {
return true;
}
} catch ( Exception e ) {
addExceptionRemark( source, propertyName, VALIDATOR_NAME, remarks, e );
return false;
}
}
示例6: basicValidation
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
/**
* @param abstractRepository
* @param update in update mode if yes already exists won't be check
* @throws RepositoryAdminException
*/
@Override
public void basicValidation( AbstractRepository abstractRepository, boolean update )
throws RepositoryAdminException
{
Configuration config = archivaConfiguration.getConfiguration();
String repoId = abstractRepository.getId();
if ( !update )
{
if ( config.getManagedRepositoriesAsMap().containsKey( repoId ) )
{
throw new RepositoryAdminException( "Unable to add new repository with id [" + repoId
+ "], that id already exists as a managed repository." );
}
else if ( config.getRepositoryGroupsAsMap().containsKey( repoId ) )
{
throw new RepositoryAdminException( "Unable to add new repository with id [" + repoId
+ "], that id already exists as a repository group." );
}
else if ( config.getRemoteRepositoriesAsMap().containsKey( repoId ) )
{
throw new RepositoryAdminException( "Unable to add new repository with id [" + repoId
+ "], that id already exists as a remote repository." );
}
}
if ( StringUtils.isBlank( repoId ) )
{
throw new RepositoryAdminException( "Repository ID cannot be empty." );
}
if ( !GenericValidator.matchRegexp( repoId, REPOSITORY_ID_VALID_EXPRESSION ) )
{
throw new RepositoryAdminException(
"Invalid repository ID. Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-)." );
}
String name = abstractRepository.getName();
if ( StringUtils.isBlank( name ) )
{
throw new RepositoryAdminException( "repository name cannot be empty" );
}
if ( !GenericValidator.matchRegexp( name, REPOSITORY_NAME_VALID_EXPRESSION ) )
{
throw new RepositoryAdminException(
"Invalid repository name. Repository Name must only contain alphanumeric characters, white-spaces(' '), "
+ "forward-slashes(/), open-parenthesis('('), close-parenthesis(')'), underscores(_), dots(.), and dashes(-)." );
}
}
示例7: isId
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
public static boolean isId(String value) {
return nonNull(value) && GenericValidator.matchRegexp(value, "^[a-zA-Z0-9]{32}$");
}
示例8: isMobile
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
public static boolean isMobile(String value) {
return nonNull(value) && GenericValidator.matchRegexp(value, "^1[34578]\\d{9}$");
}
示例9: isRegion
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
public static boolean isRegion(String value) {
return nonNull(value) && GenericValidator.matchRegexp(value, "^P[0-9]{2}-C[0-9]{3}-D[0-9]{4}$");
}
示例10: isEnglishStr
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
public static boolean isEnglishStr(String value, int min, int max) {
return nonNull(value)
&& GenericValidator.matchRegexp(value, "^[_a-zA-Z0-9]{" + min + "," + max + "}");
}
示例11: isNormalStr
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
public static boolean isNormalStr(String value, int min, int max) {
return nonNull(value)
&& GenericValidator.matchRegexp(value, "^[\\-_a-zA-Z0-9\u4e00-\u9fa5]{" + min + "," + max + "}");
}
示例12: isRichText
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
public static boolean isRichText(String value) {
return nonNull(value)
&& GenericValidator.matchRegexp(value, "^[/\"<>[email protected]#$%^&*()-=_a-zA-Z0-9\u4e00-\u9fa5]+");
}
示例13: forgotPasswordPost
import org.apache.commons.validator.GenericValidator; //导入方法依赖的package包/类
@RequestMapping(method = RequestMethod.POST, value = "/rpass", produces = "text/html")
public String forgotPasswordPost(@RequestParam(value = "password", required = true) String password,
@RequestParam(value = "cpassword", required = true) String cpassword,
@RequestParam(value = "key", required = true) String key,
@RequestParam(value = "_proceed", required = false) String proceed,
Model uiModel,HttpServletRequest httpServletRequest) {
try {
if(proceed != null){
//validate the passed key
if (! userService.user_validateForgotPasswordKey(key)) {
log.warn("Attempt to reset password with invalid key, Not successful");
uiModel.addAttribute("status", "E"); //Error
throw (new RuntimeException("Attempt to reset password with invalid key, Not successful"));
}
//check that passwords match
if (!password.equals(cpassword)) {
uiModel.asMap().clear();
uiModel.addAttribute("key", key);
uiModel.addAttribute("status", "U"); //Unmatching Passwords
return "public/rpass";
}
GlobalSettings globalSettings = applicationSettingsService.getSettings();
//Check new password strength
if(!GenericValidator.matchRegexp(password,globalSettings.getPasswordEnforcementRegex())){
uiModel.asMap().clear();
uiModel.addAttribute("key", key);
uiModel.addAttribute("status", "I"); //Unmatching Passwords
uiModel.addAttribute("passwordPolicyMsg", globalSettings.getPasswordEnforcementMessage());
return "public/rpass";
}
//All validations passed, save the HASH of the password in the database
PasswordResetRequest passwordResetRequest =userService.passwordResetRequest_findByHash(key);
User user = userService.user_findByLogin(passwordResetRequest.getLogin());
user.setPassword(password);
userService.user_updatePassword(user,passwordResetRequest);
uiModel.addAttribute("status", "S");//success
return "public/rpass";
}
else{
//cancel button
return "public/login";
}
} catch (Exception e) {
log.error(e.getMessage(),e);
throw (new RuntimeException(e));
}
}