Home arrow PHP arrow Creating a Validation Helper Class

Creating a Validation Helper Class

Helper classes seem easy to build -- almost deceptively so. If you're building a helper class to assist with a crucial function, however, such as validation, the approach you need to take may seem a bit less straightforward. This fifth article in an eight-part series on building helper classes walks you through the process, complete with hands-on examples.

  1. Creating a Validation Helper Class
  2. Review: a URL-handling helper class
  3. Creating a validation class
  4. Validating alphabetic and alphanumeric values
By: Alejandro Gervasio
Rating: starstarstarstarstar / 4
August 17, 2009

print this article



True to form, for any PHP developer with only an average background in the object-oriented paradigm, building helper classes should be a pretty straightforward task. After all, this process doesnít demand the effort required for creating a full-blown library.

Itís fair to say, though, that even when a helper is designed to perform certain tasks that at least in theory shouldnít be extremely complex, in practice things can get a bit intimidating. The reason for this is simple: there are times when a helper class needs to implement methods or functions that play a role as crucial as a much larger module or plug-in.

Of course, speaking in practical terms, categorizing a particular class as a helper or as a core library depends strongly on the context in which it will be used. But regardless of its rather intangible nature, helpers are undeniably a fundamental part of a PHP developerís toolbox.

Therefore, if youíre interested in arming yourself with the right tools to start building your own helper classes in PHP 5 with minor efforts, then donít hesitate any longer; begin reading this series of articles right away!

Before you skip over this introduction, however, it would be helpful to recall that I left off the previous article discussing how to create a URL helper class whose main functionality was implemented around the $_SERVER PHP superblobal array. Despite the simplicity of many of its methods, the class demonstrated how to utilize it without having to deal with any instances of it, since the methods were declared static, and therefore used out of the object context.

Nonetheless, this journey through the ins and outs of building helper classes with PHP 5 hasnít finished yet. In this fifth part of the series I plan to build a class that will be responsible for validating input data, either supplied by users or from a different source.

In this specific project, this validation helper will make use of the PHP filter extension to perform the pertinent checking processes, but it can be easily adapted to use custom methods as well.

Now, itís time to leave the theory behind us and start learning how to create a helper class to validate input data. Letís go!

>>> More PHP Articles          >>> More By Alejandro Gervasio

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: