Reputation: 16439
As the title suggest, I'm looking for a way to validate emails (or other string formats) using the Symfony Framework (without having to use the Form Framework).
I've done some searching around, but every example given is using the Form classes...
And I know that I can use external classes or libraries, but I'm just curious if there is something that I could use from within Symfony that'll work.
Something like this would be ideal:
$email = "[email protected]";
$validator = new sfEmailValidator(); // just using this as an example - I know it doesn't work :p
$validator->check($email); // returns true or false if it validates
Upvotes: 1
Views: 3579
Reputation: 2220
I'd reconsider using sfValidatorEmail, it's not quite accurate. Use filter_var instead (you can make your own validator based on filter_var if you want).
Upvotes: 0
Reputation: 237847
You should be able to do something like the following -- you don't need to use the form framework to use the validator framework:
$email = '[email protected]';
$v = new sfValidatorEmail();
try {
$email = $v->clean($email);
} catch (sfValidatorError $e) {
// email invalid
}
Upvotes: 8