PDA

View Full Version : Name regex doesn't work?


digitalecartoon
08-22-2007, 07:53 AM
This is my php mail script for my Flash form. I'm using utf8_decode because I noticed that Flash sends it's values utf encoded. So RenÚ would be send something like Ren%8. Using utf8 encoded fixed that and RenÚ kept being send as RenÚ.

But now I notice that apostrophe characters are regarded as false by my name regex? I've tested the regex online and a name as John O'Connor was accepted. All I did was add an escape character because the preg_match line was surrounded by apostrophes so I thought that might give a conflict.

Can someone tell me what I, Flash or PHP are doing wrong?

<?php

/* Email settings */
$to = "[email protected]";
$subject = "Een mailtje via de website";
$naam = utf8_decode($_POST["naam"]);
$email = utf8_decode($_POST["email"]);
$bericht = utf8_decode($_POST["bericht"]);

/* Check for name, including accented characters and apostrophe */
if (!preg_match('~^[a-z└- ][\'a-z└-  \-]*$~i', $naam)) {
$naam = "error";
echo "&naam=error&";
} else {
echo "&naam=correct&";
}

/* Check email address */
if (!preg_match('~^[a-z0-9][a-z0-9_.\-]*@([a-z0-9]+\.)*[a-z0-9][a-z0-9\-]+\.([a-z]{2,6})$~i', $email)) {
$email = "error";
echo "&email=error&";
} else {
echo "&email=correct&";
}

/* Strip tags message */
$bericht = strip_tags($bericht);
if (!$bericht) {
$email = "error";
echo "&bericht=error&";
} else {
echo "&bericht=correct&";
}

/* Send mail if correct */
if ($naam != "error" && $email != "error" && $bericht != "error") {

$message = "Naam:\r\n".$naam."\r\n\r\n";
$message .= "Emailadres:\r\n".$email."\r\n\r\n";
$message .= "Bericht:\r\n".stripslashes($bericht)."\r\n";

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "From: ".mb_encode_mimeheader($naam, "iso-8859-1", "Q")." <".$email.">\r\n";

mail($to, $subject, $message, $headers);

}
?>