SEM Labs

Handcrafted Pixels, Code & Title Tags

Validate

Elements

The XFL validate element validates field values submitted to a form. For example, if you wanted to check a value is no longer than a give length or if two fields have the same value.

Dissection of the XFL Validate Element

Syntax

Attributes

Attribute Value Description Required
type method name method to execute in the XFL_Sanitise class Yes
value text value to pass to the method No
select XPath query XPath query to retrive a value from data (post or population data) No
error text error to add to stack if method returns false No

Processing Information

XFL validate elements will execute the method defined in the type attribute in the XFL_Validate class. Custom validation can be created by adding new methods to the XFL_Validate class.

Built-in Functions

XFL comes with the following validators built in.

required

The required validator ensures that a field has a value, is selected or checked. If the value is set to 'no' the field will validate only if the field doesn't have a value, is selected or checked. If no value is set, it will be considered the field should have a value, be selected or checked.

Example:

Outcome:

The field will pass validation.

matches

The matches validator will ensure that a field's value matches a specified value.

Example:

Outcome:

The password_confirm field will pass validation. In this example, the select attribute of the xfl:validate element tells the parser that the password_confirm field must be the same as the password field.

differs

The differs validator will ensure that a field's value does not match a specified value.

Example:

Outcome:

The product_b field will pass validation. In this example, the select attribute of the xfl:validate element tells the parser that product_a's value must be different to that of product_b.

minLength

The minLength validator will ensure a value's length is more than equal to a specified value.

Example:

Outcome:

The field will pass validation because its length is more than 10.

maxLength

The maxLength validator will ensure a value's length is no more than or equal to a specified value.

Example:

Outcome:

The field will pass validation because its length is no more than 100.

minInt

The minInt validator will ensure a value is more than equal to a specified value.

Example:

Outcome:

The field will pass validation because it is more than 10.

maxInt

The maxInt validator will ensure a field's value is no more than or equal to a specified value.

Example:

Outcome:

The field will pass validation because it is no more than or equal to 1000.

float

The float validator will ensure a field's value is a float. Floats using scientific notation will not validate.

Example:

Outcome:

The field will pass validation because it is a float.

decimalPlaces

The decimalPlaces validator will ensure a field's value has a specified number of decimal places.

Example:

Outcome:

The field will pass validation because it has 2 decimal places.

email

The email validator will ensure a field's value is an email. It uses the regular expression: ^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z.]{2,30}$.

Example:

Outcome:

The field will pass validation.

ip

The ip validator will ensure a field's value is an IP address. It uses the regular expression: ^(25[0-5]|2[0-4][0-9]|[01][0-9][0-9])\.(25[0-5]|2[0-4][0-9]|[01][0-9][0-9])\.(25[0-5]|2[0-4][0-9]|[01][0-9][0-9])\.(25[0-5]|2[0-4][0-9]|[01][0-9][0-9])$.

Example:

Outcome:

The field will pass validation.

url

The url validator will ensure a field's value is a URL It uses the regular expression: ^(https*):\/\/([a-z0-9-.]+):*([0-9]*)\/*([^?]*)\/*\?*([^#]*)#*(.*)$

Example:

Outcome:

The field will pass validation.

regex

The regex validator will ensure that a field's value matches a regular expression. The expression must include delimiters.

Example:

Outcome:

The field will pass validation.