10.04.2018 Views

Doctrine_manual-1-2-en

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 13: Data Validation 209<br />

Chapter 13<br />

Data Validation<br />

Introduction<br />

Pulled directly from PostgreSQL Docum<strong>en</strong>tation 25 :<br />

Data types are a way to limit the kind of data that can be stored in a table. For many<br />

applications, however, the constraint they provide is too coarse. For example, a column<br />

containing a product price should probably only accept positive values. But there is no<br />

standard data type that accepts only positive numbers. Another issue is that you might want<br />

to constrain column data with respect to other columns or rows. For example, in a table<br />

containing product information, there should be only one row for each product number.<br />

<strong>Doctrine</strong> allows you to define *portable* constraints on columns and tables. Constraints give<br />

you as much control over the data in your tables as you wish. If a user attempts to store data<br />

in a column that would violate a constraint, an error is raised. This applies ev<strong>en</strong> if the value<br />

came from the default value definition.<br />

<strong>Doctrine</strong> constraints act as database level constraints as well as application level validators.<br />

This means double security: the database doesn't allow wrong kind of values and neither does<br />

the application.<br />

Here is a full list of available validators within <strong>Doctrine</strong>:<br />

validator(argum<strong>en</strong>ts) constraints description<br />

notnull NOT NULL Ensures the 'not null' constraint in both application<br />

and database level<br />

email<br />

Checks if value is valid email.<br />

notblank NOT NULL Checks if value is not blank.<br />

nospace<br />

past<br />

future<br />

minl<strong>en</strong>gth(l<strong>en</strong>gth)<br />

CHECK<br />

constraint<br />

Checks if value has no space chars.<br />

Checks if value is a date in the past.<br />

Checks if value is a date in the future.<br />

Checks if value satisfies the minimum l<strong>en</strong>gth.<br />

25. http://www.postgresql.org/docs/8.2/static/ddl-constraints.html<br />

----------------- Brought to you by

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!