View Single Post
  #1 (permalink)  
Old 07-12-2006, 01:12 AM
kenwvs kenwvs is offline
Registered User
 
Join Date: Jun 2006
Posts: 10
A Function for a PHP Form Validating

I am trying to write a form validating script and have most of the functions figured out. I have a couple where I want the opportunity to leave it blank, but, if they choose to fill it in, I want it to meet certain requirements.

Example. The field can be left blank, but, if they put anything in the field, it must be in the form of a email address. (I know how the format for an email is

function checkEmail($email) { //Check Email Format
$pattern = "/^[A-z0-9\._-]+"
. "@"
. "[A-z0-9][A-z0-9-]*"
. "(\.[A-z0-9_-]+)*"
. "\.([A-z]{2,6})$/";
return preg_match ($pattern, $email);

but how do I add that it can be blank also.

The same thing except it would be in a dollar value, but could be blank.

Thanks,

Ken
Reply With Quote