I thought some of you symfony developers out there might appreciate the following form validators. They have been incredibly convenient, and were incredibly simple to write. I hope they come in handy:
- sfValidatorPhone: Validates a phone number using regex
- sfValidatorZip: Validates a zip code using regex
- sfValidatorUrl: Validates a url using regex
- sfValidatorCCExpirationDate (1.2, 1.4): validates the month/year on a credit card
- sfValidatorCreditCardNumber: validates a credit card number with an optional card type parameter
- sfValidatorCoupon: Used in payment forms to validate a coupon
What other useful validators should I include?
***** UPDATE *****
Symfony versions 1.3 and 1.4 broke backwards compatibility with some of these validators. I’ve added a link to each symfony version to fix this.


RSS Feed
Thanks for sharing these! You have saved me some time and research.
Thanks a lot! I was searching for a phone number validator and was happy to find this great collection. FWIW, Symfony 1.3 includes an sfValidatorUrl class.
Exactly what I was looking for (Zip and Phone). Thank you.
Hell yeah! I was just thiiiiiis close to re-implementing sfValidatorPhone, but then, in a flash, I remembered, “I think Brent already did this somewhere.”
And of course, you did. Thanks for putting this up!
It’s quite possible that I’m not using your sfValidatorCCExpirationDate properly, but it seems that I must change the method signature to ‘convertDateArrayToString’ in order for it to override the method in sfValidatorDate. I’m using Symfony 1.4.1 if that helps.
I just found this out myself… took me about a half hour. I have updated my post accordingly. Thanks for the update, David!