Field validator definitions

PolicyCenter stores field validator definitions in the fieldvalidators.xml file, located in Guidewire Studio under configuration > config > fieldvalidators. The fieldvalidators.xml file contains a list of validator specifications for individual fields in PolicyCenter. The fieldvalidators.xml file contains the following sections:

XML element

Description

More information

<FieldValidators>

Top XML element for the fieldvalidators.xml file.

<FieldValidators>

<ValidatorDef>

Subelement that defines all of the validators. Each validator must have a unique name by which you can reference it.

<ValidatorDef>

Using the fieldvalidators.xml file, you can do the following:

  • You can modify existing validators. For example, it is common for each installation site to represent policy numbers differently. You can define field validation to reflect these changes.
  • You can add new validators for existing fields or custom extension fields.

The following XML example illustrates the structure of the fieldvalidators.xml file:

<FieldValidators>
  <ValidatorDef name="Email"
                description="Validator.Email"
                input-mask=""
                value=".+@.+"/>
  <ValidatorDef name="SSN"
                description="Validator.SSN"
                input-mask="###-##-####"
                value="[0-9]{3}-[0-9]{2}-[0-9]{4}|[0-9]{2}-[0-9]{7}?"
                />
  ...
</FieldValidators>

In the previous example, each validator definition specifies a value and an input-mask. These attributes have different uses, as follows:

value

A value is a regular expression that the field value must match for the data to be valid. PolicyCenter persists this value to the database, including any defined delimiters or characters other than the # character.

input-mask

An input-mask, which is optional, assists the user in entering valid data. PolicyCenter displays the input mask when the field opens for editing. For example, a # character indicates that the user must enter a digit for this character. These characters disappear when the user starts to enter data.

The input mask guides the user to enter to valid sequences for the regular expression defined in the value attribute. After the user enters a value, PolicyCenter uses the regular expression to validate the field data as it sets the field on the object.

This topic includes the following:

<FieldValidators>

The <FieldValidators> element is the root element in the fieldvalidators.xml file. It contains the XML subelement <ValidatorDef>.

<ValidatorDef>

The <ValidatorDef> subelement of <FieldValidators> is the beginning element for the definition of a validator. This element has the following attributes:

  • description
  • floor, ceiling
  • input-mask
  • name
  • placeholder-char
  • validation-level
  • validation-type
  • value

description

The description attribute specifies the validation message to show to a user who enters bad input. The description refers to a key in the display_languageCode.properties file that contains the actual description text. The naming convention for this display key is Validator.validator_name.

In the display text in the properties file, {0} represents the name of the field in question. PolicyCenter determines this at runtime dynamically.

floor, ceiling

The floor and ceiling attributes are optional attributes that specify the minimum (floor) and maximum (ceiling) values for the field. For example, you can limit the range to 100-200 by setting floor="100" and ceiling="200".

Use floor and ceiling range values for numeric fields only. For example, use the floor and ceiling attributes to define a Money validator:

<ValidatorDef description="Validator.Money" 
              input-mask="" name="Money"
              ceiling="9999999999999999.99" 
              floor="-9999999999999999.99" 
              value=".*"/>

input-mask

The input-mask attribute is optional. It specifies a visual indication of the characters that the user can enter. PolicyCenter displays the input mask temporarily to the user during data entry. When the user starts to enter text, the input mask is no longer visible.

The input mask definition consists of the # symbol and other characters:

  • The # symbol represents any character the user can type.
  • Any other character represents itself in a non-editable form. For example, in an input mask of ###-###-##, the two hyphen characters are a non-editable part of the input field.
  • Any empty input mask of "" is the same as not having the attribute at all.
  • A special case is a mask with fixed characters on the end. PolicyCenter displays those characters outside of the text field. For example ####mph appears as a field #### with mph on the outside end of it.

name

The name attribute specifies the name of the validator. A field definition uses this attribute to specify which validator applies to the field.

placeholder-char

The placeholder-char attribute specifies a replacement value for the input mask display character, which defaults to a period (.) For example, use the placeholder-char attribute to display a dash character instead of the default period.

validation-level

This attribute can be set to one of the following values:

Attribute

Description

none

Disables the validator.

relaxed

Ignores warnings or partial validation.

strict (default)

Treats partially validation or warnings as errors.

validation-type

Specifies whether to use a regular expression or Gosu class for the validation.

This attribute can be set to one of the following values:

Attribute

Description

gosu

The value of the <ValidatorDef> is a Gosu class. The Gosu class must extend FieldValidatorBase and override the validate method. See gw.api.validation.PhoneValidator for an example. Ensure that any Gosu validators that you define are low-latency for performance reasons.

regex (default)

The value of the <ValidatorDef> defines a regular expression that PolicyCenter uses to validate data entered into a field that uses the field validator.

value

The value attribute specifies the acceptable values for the field. It is in the form of a regular expression. PolicyCenter does not persist this value (the regular expression definition) to the database.

Use regular expressions with String values only. Use floor and ceiling range values for numeric fields, for example, Money.

PolicyCenter uses the Java regex package described in the following location for regular expression parsing:

https://docs.oracle.com/javase/8/docs/api/java/util/regex/package-summary.html

The following list describes some of the more useful items:

()

Parentheses define the order in which PolicyCenter evaluates an expression, just as with any parentheses.

[]

Brackets indicate acceptable values. For example:

  • [Mm] indicates the letters M or m.
  • [0-9] indicates any value from 0 to 9.
  • [0-9a-zA-Z] indicates any alphanumeric character.

{}

Braces indicate the number of characters. For example:

  • [0-9]{5} allows five positions containing any character (number) between 0 and 9.
  • {x} repeats the preceding value x times. For example, [0-9]{3} indicates any 3-digit integer such as 031 or 909, but not 16.
  • {x,y} indicates the preceding value can repeat between x and y times. For example, [abc]{1,3} allows values such as cab, b, or aa, but not rs or abca.

?

A question mark indicates one or zero occurrences of the preceding value. For example, [0-9]x? allows 3x or 3 but not 3xx. ([Mm][Pp][Hh])? means mph, MpH, MPH, or nothing.

()?

Values within parentheses followed by a question mark are optional. For example, (-[0-9]{4})? means that you can optionally have four more digits between 0 and 9 after a dash -.

*

An asterisk means zero or more of the preceding value. For example, (abc)* means abc or abcabc but not ab.

+

A plus sign means one or more of the preceding value. For example, [0-9]+ means any number of integers between 0 and 9 (but none is not an option).

.

A period is a wildcard character. For example:

  • .* means anything.
  • .+ means anything but the empty string.
  • ... means any string with three characters.