<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.7.2" -->
<rss version="2.0">
    <channel>
        <title>GettingStarted:validation[ Search for &quot;&quot;]</title>
        <description></description>
        <link>http://xataface.com/wiki/index.php?-action=single_record_search&amp;-table=wiki&amp;page_id=%3D79&amp;-cursor=0&amp;-skip=0&amp;-limit=30&amp;-mode=list&amp;--subsearch=</link>
        <lastBuildDate>Wed, 19 Jun 2013 05:12:21 +0100</lastBuildDate>
        <generator>FeedCreator 1.7.2</generator>
        <item>
            <title>GettingStarted:validation</title>
            <link>http://www.xataface.com/wiki/GettingStarted:validation</link>
            <description>&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Field&lt;/th&gt;&lt;th&gt;Value&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Page name&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;GettingStarted:validation&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Page id&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;79&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Page title&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;Form Validation&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Content&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;
&lt;h2 id=&quot;toc0&quot;&gt;Form Validation&lt;/h2&gt;
&lt;p&gt;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:&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt; The Username field is required.&lt;/li&gt;
    &lt;li&gt; The Username must be between 6 and 16 characters long.&lt;/li&gt;
    &lt;li&gt; The password must have at least one letter and one digit.&lt;/li&gt;
    &lt;li&gt; The Email field must contain a valid email address.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;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.&lt;/p&gt;


&lt;h3 id=&quot;toc1&quot;&gt;Example 1: Make 'Username' a required field&lt;/h3&gt;
 
&lt;pre&gt;&lt;code&gt;[Username]
    validators:required = true
    validators:required:message = &amp;quot;Username is required&amp;quot;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Placing the above inside the fields.ini file will cause the Username field to be a required field.&lt;/p&gt;


&lt;h3 id=&quot;toc2&quot;&gt;Example 2: Username must be between 6 and 16 characters long&lt;/h3&gt;
&lt;p&gt;For this rule we will use a regular expression. 
&lt;pre&gt;&lt;code&gt;[Username]
    validators:regex = &amp;quot;/^.{6,16}$/&amp;quot;
    validators:regex:message = &amp;quot;Username must be between 6 and 16 characters long&amp;quot;&lt;/code&gt;&lt;/pre&gt;

&lt;/p&gt;


&lt;h3 id=&quot;toc3&quot;&gt;Example 3: Email field must contain a valid email address&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;[Email]
    validators:email = true
    validators:regex:message = &amp;quot;Email must contain a valid email address&amp;quot;&lt;/code&gt;&lt;/pre&gt;


&lt;h3 id=&quot;toc4&quot;&gt;Available validation rules&lt;/h3&gt;
&lt;p&gt;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:&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt; required&lt;/li&gt;
    &lt;li&gt; maxlength&lt;/li&gt;
    &lt;li&gt; rangelength&lt;/li&gt;
    &lt;li&gt; regex&lt;/li&gt;
    &lt;li&gt; email&lt;/li&gt;
    &lt;li&gt; emailorblank&lt;/li&gt;
    &lt;li&gt; lettersonly&lt;/li&gt;
    &lt;li&gt; alphanumeric&lt;/li&gt;
    &lt;li&gt; numeric&lt;/li&gt;
    &lt;li&gt; nopunctuation&lt;/li&gt;
    &lt;li&gt; nonzero&lt;/li&gt;
&lt;/ul&gt;


&lt;h3 id=&quot;toc5&quot;&gt;Default validation rules&lt;/h3&gt;
&lt;p&gt;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 'required' field. At the time of this writing, that is the only 'default' validation rule applied, but more may be added in the future if their addition makes sense.&lt;/p&gt;

&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Keywords&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;form validation,required field,validation rules&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Language&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;en&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;</description>
            <author>GettingStarted:validation</author>
        </item>
    </channel>
</rss>
