validators:NAME fields.ini directive
Return to fields.ini file
Synopsis
In the fields.ini file you can specify validation rules to be applied to any field by adding the validators:NAME directive in that field’s section of the fields.ini file.
Available Validators
| Name | Description | Value | Version |
|---|---|---|---|
| required | Field is required | 1 | All |
| maxlength | Maximum number of characters allowed. | $length | All |
| minlength | Minimum number of characters allowed. | $length | All |
| rangelength | Range (min and max) characters allows | $min,$max | All |
| Input must be syntactically correct email address. | 1 | All | |
| emailorblank | Accepts an email address or a blank field. | 1 | All |
| regex | Input must match the provided regular expression. | A regular expression | All |
| lettersonly | Input must contain only letters (i.e. [a-zA-Z] | 1 | All |
| numeric | The input must contain a valid positive or negative integer or decimal number. | 1 | All |
| nopunctuation | The input must not contain any of these characters: ( ) . / * ^ ? # ! @ $ % + = , “ ‘ > < ~ [ ] { }. | 1 | All |
| nonzero | The input must not begin with zero. | 1 | All |
| uploadedfile | The element must contain a successfully uploaded file. | 1 | All |
| maxfilesize | The uploaded file must be no more than $size bytes. | $size | All |
| filename | The uploaded file must have a filename that matches the regular expression $file_rx. | $file_rx | All |
Examples
To make a the first_name field required we add the following to the fields.ini file:
[first_name]
validators:required=1
Note that fields that are declared NOT NULL in the database are required by default.. If you wanted to remove the required validator from a field that is NOT NULL in the database you would add the following to the fields.ini file:
[first_name]
validators:required=0
See Also
- fieldname__validate - For more complex validation you can define the fieldname__validate method in the Table Delegate Class.
- HTML_QuickForm article going over HTML_Quickform validation. Dataface’s forms are built on HTML_QuickForm.
- Form Validation - Section from getting started tutorial introducing form validation in a tutorial format.
var disqus_identifier = ‘xataface.com/wiki/validators’; (function() { var dsq = document.createElement(‘script’); dsq.type = ‘text/javascript’; dsq.async = true; dsq.src = ‘http://xataface.disqus.com/embed.js’; (document.getElementsByTagName(‘head’)[0] || document.getElementsByTagName(‘body’)[0]).appendChild(dsq); })(); blog comments powered by Disqus
//<![CDATA[ (function() { var links = document.getElementsByTagName(‘a’); var query = ‘?’; for(var i = 0; i < links.length; i++) { if(links[i].href.indexOf(‘#disqus_thread’) >= 0) { query += ‘url’ + i + ‘=’ + encodeURIComponent(links[i].href) + ‘&’; } } document.write(‘