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:

  1. sfValidatorPhone: Validates a phone number using regex
  2. sfValidatorZip: Validates a zip code using regex
  3. sfValidatorUrl: Validates a url using regex
  4. sfValidatorCCExpirationDate (1.2, 1.4): validates the month/year on a credit card
  5. sfValidatorCreditCardNumber: validates a credit card number with an optional card type parameter
  6. 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.

6 comments

  • Ethan - October 5, 2009

    Thanks for sharing these! You have saved me some time and research.

  • Stereoscott - November 6, 2009

    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.

  • Cryo - January 28, 2010

    Exactly what I was looking for (Zip and Phone). Thank you.

  • Joshua - March 29, 2010

    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!

  • David - April 1, 2010

    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.

  • admin - April 29, 2010

    I just found this out myself… took me about a half hour. I have updated my post accordingly. Thanks for the update, David!

Add comment