<?xml version="1.0"?>
<record><wiki id="wiki?page_id=79">
	<page_name>GettingStarted:validation</page_name>
	<page_id>79</page_id>
	<page_title>Form Validation</page_title>
	<content>==Form Validation==

Xataface allows you to add validation rules to fields using the fields.ini file
A common requirement for forms is to have some validation rules. Here are some example validation rules:

* The Username field is required.
* The Username must be between 6 and 16 characters long.
* The password must have at least one letter and one digit.
* The Email field must contain a valid email address.

There is no end to the types of things that you will need to validate. Xataface takes care of most of this for you with both client-side (javascript) and server-side validation. All you have to do is define some validation rules in the fields.ini file.

===Example 1: Make &apos;Username&apos; a required field===
&lt;code&gt;
[Username]
	validators:required = true
	validators:required:message = &quot;Username is required&quot;
&lt;/code&gt;

Placing the above inside the fields.ini file will cause the Username field to be a required field.

===Example 2: Username must be between 6 and 16 characters long===

For this rule we will use a regular expression.
&lt;code&gt;
[Username]
	validators:regex = &quot;/^.{6,16}$/&quot;
	validators:regex:message = &quot;Username must be between 6 and 16 characters long&quot;
&lt;/code&gt;

===Example 3: Email field must contain a valid email address===

&lt;code&gt;
[Email]
	validators:email = true
	validators:regex:message = &quot;Email must contain a valid email address&quot;
&lt;/code&gt;

===Available validation rules===

Xataface uses the PEAR library HTML_Quickform for validation, so any of the validators available in this package will be available in Xataface. Some of the available validation rules include:

* required
* maxlength
* rangelength
* regex
* email
* emailorblank
* lettersonly
* alphanumeric
* numeric
* nopunctuation
* nonzero

===Default validation rules===

There are certain validation rules that are automatically applied to fields of with certain characteristics. For example, any field designated NOT NULL in the SQL table definition will automatically be a &apos;required&apos; field. At the time of this writing, that is the only &apos;default&apos; validation rule applied, but more may be added in the future if their addition makes sense.

</content>
	<keywords>form validation,required field,validation rules</keywords>
	<language>en</language>
	<original_page></original_page>
</wiki></record>