Common validation rules

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Common validation rules

Post by onion2k »

I'm rewriting my form handler ... part of the update is the inclusion of a nicer way of adding validation to form objects. It's something that's been done a million times before, but I fancied doing my own (mainly so I can make it interact with Twig nicely, but anyway).

So far my validation rules consist of;

Required - Field must be completed
Minimum length - Field must be at least a certain number of characters
Maximum length - Field must be no more than a certain number of characters
Alpha - Field must be letters only.
Alphanumeric - Field must be letters or numbers only.
Numeric - Field must be numbers only.
Equals - Field must be the same as something (another field, a session variable, etc).
Enum - Field must be the same as something in a list of options.
Email - Field must be a valid email address.
URL - Field must be a valid URL.
Regexp - Field must match a regular expression.

Have I missed anything obvious? The regexp option means users will be able to define their own rules easily enough, but if there's something that's used frequently then I'd rather include it now.
User avatar
pcoder
Forum Contributor
Posts: 230
Joined: Fri Nov 03, 2006 5:19 am

Re: Common validation rules

Post by pcoder »

What about :
1.date: different date format
2.range: value between let say x n y
Post Reply