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. Goes well with sfWidgetFormCCExpirationDate.
- 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!
Hi – just been looking for a credit card validator for sf1.4 and came across this page.
I think there is a problem with the regex in sfValidatorCreditCardNumber for switch / jcb /enroute.
I think the square brackets should be parentheses if you want to match the 4 digits as a group, e.g.
/^(4903|4911|4936|5641|6333|6759|6334|6767)d{12}$/
Anyway, I realise its a bit late now but thought I’d add a note for anyone else in the same boat.
this is very use ful validatiors…. thanx for this
:)
Thanks!!
Amazing !!! Thanks