i need some help about validating icno(identity card no eg: 820411-03-5325) and dob(date of birth eg: 1982-04-11). how am i suppose to use ereg function which can validate a dash?? following is the code that i use…
[code]<?php
include(“conn.inc”);
$label_array = array("fname" => "First Name",
"lname" => "Last Name",
"icno" => "IC Number",
"uname" => "Username",
"pass" => "Password",
"dob" => "Date of Birth",
"addr" => "Address",
"pcode" => "Postcode",
"htel" => "Home Telephone Number",
"otel" => "Office Telephone Number",
"mtel" => "Mobile Telephone Number",
"alg" => "Allergic",
"occpy" => "Occupation");
foreach($_POST as $key => $value)
{
if($value == "")
{
if($key != "addr" and $key != "pcode" and $key != "htel" and $key != "otel" and $key != "mtel" and $key != "alg" and $key != "occpy")
{
$blank_array[$key] = "blank";
}
}
elseif($key == "fname" or $key == "lname")
{
if(!ereg("^[A-Za-z' -]{1,50}$",$_POST[$key]))
{
$bad_format[$key] = "bad";
}
}
elseif($key == "icno")
{
if(!ereg('^([0-9]{6})(-[0-9]{2})?(-[0-9]{4})?$',$key))
{
$bad_format[$key] = "bad";
}
}
elseif($key == "dob")
{
if(!ereg('^([0-9]{4})[-|/]?([0-9]{2})[-|/]?([0-9]{2})$',$key))
{
$bad_format[$key] = "bad";
}
}
}
if(@sizeof($blank_array) > 0 or @sizeof($bad_format) > 0)
{
if(@sizeof($blank_array) > 0)
{
echo "<b>You didn't fill one or more of the required field(s).</b><br>";
echo "<b>Please enter value for : </b>";
foreach($blank_array as $key => $value)
{
echo "{ $label_array[$key] } ";
}
}
if(@sizeof($bad_format) > 0)
{
echo "<b>One or more fields appears to be incorrect</b><br>";
echo "<b>Please correct the following fields : </b>";
foreach($bad_format as $key => $value)
{
echo "( {$label_array[$key] } ";
}
}
include("add_pat.php");
exit();
}
$query="SELECT * FROM patient";
#$result=mysql_query($query,$conn);
if(mysql_query($query,$conn)){
$sql="INSERT INTO patient VALUES('', '$_POST[fname]', '$_POST[lname]', '$_POST[uname]', '$_POST[pass]', '$_POST[icno]', '$_POST[dob]', '$_POST[addr]', '$_POST[pcode]', '$_POST[htel]', '$_POST[otel]', '$_POST[mtel]', '$_POST[gend]', '$_POST[alg]' , now(), '$_POST[occpy]','' )";
$result2 = mysql_query($sql,$conn) or die (mysql_error());
echo "<p align="center"><b><font size="1" color="000080" face="Arial">Patient has been added into database!!</font></b></p>";
include("add_pat.php");
}
else{
echo "Error adding patient into database!";
include("add_pat.php");
}
?>[/code]