Class RegexFieldValidator
java.lang.Object
org.apache.struts2.validator.validators.ValidatorSupport
org.apache.struts2.validator.validators.FieldValidatorSupport
org.apache.struts2.validator.validators.RegexFieldValidator
- All Implemented Interfaces:
- FieldValidator,- ShortCircuitableValidator,- Validator
- Direct Known Subclasses:
- CreditCardValidator,- EmailValidator
 Validates a string field using a regular expression.
 
 
 
- fieldName - The field name this validator is validating. Required if using Plain-Validator Syntax otherwise not required
- regexp - The RegExp expression
- caseSensitive - Boolean (Optional). Sets whether the expression should be matched against in a case-sensitive way. Default is true.
- trim - Boolean (Optional). Sets whether the expression should be trimmed before matching. Default is true.
- regexExpression - String (Optional). Defines regExp expression as an OGNL expression - will be evaluated to String
- caseSensitiveExpression - String (Optional). Defines caseSensitive param as an OGNL expression - will be evaluated to Boolean.
- trimExpression - String (Optional). Defines trim param as an OGNL expression - will be evaluated to Boolean
You can mix normal params with expression aware params but thus was not tested
Do not use ${regexExpression}, ${caseSensitiveExpression} and ${trimExpression} as an expression as this will turn into infinitive loop!
 
 <validators>
     <!-- Plain Validator Syntax -->
     <validator type="regex">
         <param name="fieldName">myStrangePostcode</param>
         <param name="regex"><![CDATA[([aAbBcCdD][123][eEfFgG][456])]]></param>
     </validator>
     <!-- Field Validator Syntax -->
     <field name="myStrangePostcode">
         <field-validator type="regex">
             <param name="regex"><![CDATA[([aAbBcCdD][123][eEfFgG][456])]]></param>
         </field-validator>
     </field>
     <!-- Field Validator Syntax with expressions -->
     <field name="myStrangePostcode">
         <field-validator type="regex">
             <param name="regexExpression">${regexValue}</param> <!-- will be evaluated as: String getRegexValue() -->
             <param name="caseSensitiveExpression">${caseSensitiveValue}</param> <!-- will be evaluated as: boolean getCaseSensitiveValue() -->
             <param name="trimExpression">${trimValue}</param> <!-- will be evaluated as: boolean getTrimValue() -->
         </field-validator>
     </field>
 </validators>
 
 - Author:
- Quake Wang
- 
Field SummaryFields inherited from class org.apache.struts2.validator.validators.FieldValidatorSupportcurrentValue, fieldName, typeFields inherited from class org.apache.struts2.validator.validators.ValidatorSupportdefaultMessage, EMPTY_STRING, messageKey, stack, textProviderFactory
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptiongetRegex()booleanbooleanisTrimed()voidsetCaseSensitive(Boolean caseSensitive) voidsetCaseSensitiveExpression(String caseSensitiveExpression) voidvoidsetRegexExpression(String regexExpression) voidvoidsetTrimExpression(String trimExpression) Allows specify trim param as an OGNL expressionvoidThe validation implementation must guarantee that setValidatorContext will be called with a non-null ValidatorContext before validate is called.protected voidvalidateFieldValue(Object object, String value, String regexToUse) Methods inherited from class org.apache.struts2.validator.validators.FieldValidatorSupportgetCurrentValue, getFieldName, getValidatorType, setFieldName, setValidatorTypeMethods inherited from class org.apache.struts2.validator.validators.ValidatorSupportaddActionError, addFieldError, getDefaultMessage, getFieldValue, getMessage, getMessageKey, getMessageParameters, getValidatorContext, isShortCircuit, parse, setDefaultMessage, setMessageKey, setMessageParameters, setShortCircuit, setTextProviderFactory, setValidatorContext, setValueStackMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.struts2.validator.ValidatorgetDefaultMessage, getMessage, getMessageKey, getMessageParameters, getValidatorContext, setDefaultMessage, setMessageKey, setMessageParameters, setValidatorContext, setValueStack
- 
Constructor Details- 
RegexFieldValidatorpublic RegexFieldValidator()
 
- 
- 
Method Details- 
validateDescription copied from interface:ValidatorThe validation implementation must guarantee that setValidatorContext will be called with a non-null ValidatorContext before validate is called.- Parameters:
- object- the object to be validated.
- Throws:
- ValidationException- is thrown if there is validation error(s).
 
- 
validateFieldValue
- 
getRegex- Returns:
- Returns the regular expression to be matched.
 
- 
setRegex- Parameters:
- regex- the regular expression to be matched
 
- 
setRegexExpression- Parameters:
- regexExpression- the regular expression as an OGNL expression to be matched
 
- 
isCaseSensitivepublic boolean isCaseSensitive()- Returns:
- Returns whether the expression should be matched against in
         a case-sensitive way.  Default is true.
 
- 
setCaseSensitive- Parameters:
- caseSensitive- whether the expression should be matched against in a case-sensitive way. Default is- true.
 
- 
setCaseSensitiveExpression- Parameters:
- caseSensitiveExpression- Allows specify caseSensitive param as an OGNL expression
 
- 
isTrimedpublic boolean isTrimed()- Returns:
- Returns whether the expression should be trimed before matching.
 Default is true.
 
- 
setTrim- Parameters:
- trim- whether the expression should be trimed before matching. Default is- true.
 
- 
setTrimExpressionAllows specify trim param as an OGNL expression- Parameters:
- trimExpression- trim param as an OGNL expression
 
 
-