I am trying to validate an user's input.  I can get the ereg function to
work if I just type in the pattern I'm searching for but my problem is I
want to build the pattern through a variable first and then use that
variable in the ereg function.

For example, I want to check an input that's only text and only between 5 to
20 characters in length.  Is this possible?

function check_input($user_input, $min=0, $max=0, $text=false,
                     $number=false, $special=false, $default="")
{
  if ($text) $pattern .= "a-zA-Z";
  if ($number) $pattern .= "0-9";
  if ($special) $pattern .= "[:space:]";

  if  (ereg("^[$pattern]{$min,$max}$", $user_input))
    return $user_input;
  else
    return $default;
}

Also, which of the following special characters is considered safe to
accept?  I am just allowing spaces now but would like as many of the below
characters to be included.

~ ` ! @ # $ % ^ & * ( ) _ + - = [ ] \ { } | : " ; ' < > ? , . /


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to