Page 1 of 1

Need help with this form validation Please

Posted: Mon Jan 25, 2010 2:31 pm
by kevinkhan
I have a from with this field in it

<label>Email:</label>
<input type="text" name="email" id="email" />

I want to make sure a user enters the correct format of an email address.. Is there anyway of checking this??

if possible could you right it in this format

Code: Select all

$fields_with_lengths = array('menu_name' => 30);
        foreach($fields_with_lengths as $fieldname => $maxlength)
          {
          if(strlen(trim(mysql_prep($_POST[$fieldname]))) > $maxlength) 
            {
            $errors[] = $fieldname;
            }
          }
as i want make an error array with all the errors from other fields as well..

Thanks for your help..

Re: Need help with this form validation Please

Posted: Mon Jan 25, 2010 3:13 pm
by AbraCadaver
Not sure what you mean about that format, but here is the basic method:

Code: Select all

if(!filter_var($fieldname, FILTER_VALIDATE_EMAIL)) {
    $errors[] = $fieldname;
}