class design - validating user input
<p>I use the clas below to validate user input.  Originally it was just a collection of static functions grouped together.  </p>

<p>However, I modifed it to an object style and added in a private memeber to hold the user input array.  What is the next step to making this class adaptable, i.e. more generic so that it can be used by others as part of a library?</p>

<p>$message is the text displayed to the user on a validation fail.  </p>

<p>Library Code:</p>

<pre><code>class validate
  {
  private $input;
  function __construct($input_arg)
    {
    $this-&gt;input=$input_arg;
    } 
  function empty_user($message)    
    {
    if((int)!in_array('',$this-&gt;input,TRUE)) return 1;
    echo $message;return 0; 
    }
  function name($message)          
    {
    if(preg_match('/^[a-zA-Z-\.]{1,40}$/',$this-&gt;input['name'])) return 1;
    echo $message;return 0; 
    }
  function email($message)
    {
    if(preg_match('/^[a-zA-Z0-9._s-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{1,4}$/',$this-&gt;input['email'])) return 1;
    echo $message;return 0; 
    }
  function pass($message)
    {
    if(preg_match('/^[a-zA-Z0-9!@#$%^&amp;*]{6,20}$/',$this-&gt;input['pass'])) return 1;
    echo $message;return 0;
    }
  }
</code></pre>

<p>Application Code:</p>

<pre><code>  function __construct()
    {
    parent::__construct();
    $obj=check_new($this-&gt;_protected_arr);
    $a='&lt;si_f&gt;Please enter both an email and a password!';
    $b='&lt;si_f&gt;Please enter a valid email!';
    $c='&lt;si_f&gt;Please enter a valid password!';
    if($obj-&gt;empty_user($a) &amp;&amp; $obj-&gt;email($b) &amp;&amp; $obj-&gt;pass($c) &amp;&amp; self::validate())
      {
      self::activate_session();
      echo "&lt;si_p&gt;";
      }
    }
</code></pre>
