Valang allows you to specify other date formats. For each custom date format you add to
the date parser you need to provide a regular expression that matches the date format. Refer
to Table 9-4 for examples of regular expressions. To make sure your regular expressions con-
sume date literals entirely use “^” at the start of the regular expression and “$” at the end. In
regular expressions “^” signifies the start of the literal, while “$” signifies the end.
Date formats are parsed by java.text.SimpleDateFormatand must use the notation
implemented by this class. Look at the SimpleDateFomat javadocfor more details.
To configure Valang with custom date formats, inject them as a Mapin the
dateParserRegistrationsproperty, as shown in Listing 9-14.
Listing 9-14.Example of Registering Custom Date Formats with Valang
<bean id="easyAddressValidator" class=➥
"org.springmodules.validation.ValangValidatorFactoryBean">
<property name="syntax">
<value><![CDATA[
{ order.timestamp :? >= [200406] :
'No orders dating before june 2004 can be processed.' }
]]></value>
</property>
<property name="dateParserRegistrations">
<props>
<prop key="^\\d{6}$">yyyyMM</prop>
<prop
key="^\\d{4}\\-\\d{2}\\-\\d{2}\\s+\\d{2}:\\d{2}$">
yyyy-MM-dd HH:mm</prop>
</props>
</property>
</bean>
Valang has a number of built-in functions, as shown in Table 9-5. We’ve already discussed
the length function in Listing 9-8.
Table 9-5.Built-in Functions in Valang
Function Name Description
length Returns the length of the return value of the toString()method of the target
object.
len See length.
size See length.
upper Returns the return value of the toString()method of the target object in
uppercase characters.
lower Returns the return value of the toString()method of the target object in
lowercase characters.
!NOT operation on booleantarget objects.
resolve Resolves a message code through a message source.
274 CHAPTER 9 ■VALIDATION