Even more undocumented validator-stuff

March 14, 2007

After i found out about the pre-defined categories in sfFileValidator i got curious and took a look at the other validator classes. Turns out there is even more undocumented, useful but also useless, code.
Here are the hidden features/classes i found:

sfNumberValidator type

In the sfNumberValidator you can specify the type of the number. For example, you could check if the type is a float number.
Possible values are:

  • any (default)
  • decimal
  • float
  • int
  • integer

Please note that decimal/float and int/integer are the same.

The error message is passed in the type_error parameter.
Here’s a small example for validating a float/decimal number:

      msg: field is required
      type: float
      type_error: Please enter a float number

sfEmailValidator check_domain

Also undocumentd on the symfony-website is the check_domain parameter for the sfEmailValidator.
When setting this parameter to true the validator uses the checkdnsrr function to check the DNS for A and MX records, which is very useful if you want to get sure that the mail-server is reachable.
If no record is found, it returns the value stored in the email_error parameter.
A small example:

      msg: field is required
      check_domain: true
      email_error: not a valid email address


The sfHtmlValidator isn’t even mentioned in the list of the Standard Symfony Validators and when looking at the source code this is completely understandable, because this validator is totally useless.
First, the validator uses the strip_tags function on the value to remove all tags from it:

if (trim(strip_tags($value)) ==)

if the value is empty it checks if it has a img or object tag in it:

if (preg_match(/<img/i, $value) || preg_match(/<object/i, $value))

and returns true if it found one of those or else returns false.
I would be very interested to know why this validator is shipped with symfony 1.0 ;-)


There is another undocumented validator in symfony – the sfDateValidator. Unfortunately this helper just produces a bunch of php errors and doesn’t seem to work at all.
Looking at the source code, this helper was intended to validate a date or compare two dates with each other.
It would be great to have such a helper working, especially with the compare-feature this might become very useful.


2 Responses to “Even more undocumented validator-stuff”

  1. Markus Says:

    maybe you could get some idears from the smartyvalidate validators to complete the datevalidator… but also a look on the other validators from smartyvalidate would be aprecated


  2. Simon Says:

    Heh, the documentation on the email validation class was pretty limited on the symfony site…


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: