hi alll
i had to have a code for email validation using function...... for that i did write a code for the validation but not able get the result
<?php
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);
// check an email address is possibly valid
if (isset ($POST['submit'])){
$address = $POST['address'];
if (eregi("[@ ]+@[@ ]+.[@ ]+$", $address)){
print "TRUE";
}else{
print "FALSE";
}
} else {
print '<form action="handle_reg.php" method="post">
<p>EMAIL: <input type="text" name="address" size="20" /></p>
<input type="submit" name="submit" value="validate" />
</form>';
?>
can any one help me out with the code????
email validation?? function
You need another closing brace before the "?>" to close the final else block.
i wanted to use a fuctions in my code how can i do so???????????????
<?php
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);
// check an email address is possibly valid
if (isset ($POST['submit']{
function email_validate($address){
$address = $POST['address'];
if (eregi("[@ ]+@[@ ]+.[@ ]+$", $address)){
print "TRUE";
}else{
print "FALSE";
}
}
} else {
print '<form action="handle_reg.php" method="post">
<p>EMAIL: <input type="text" name="address" size="20" /></p>
<input type="submit" name="submit" value="validate" />
</form>';
}
?>
i am unable to get the result can you help me out???
You need another closing brace before the "?>" to close the final else block.
PS: please make use of the [php] bbcode tag when posting code here.
You need to actually call the function...
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);
// check an email address is possibly valid
if (isset ($_POST['submit']{
validateEmail($_POST['address']);
}
else
{
print '<form action="handle_reg.php" method="post">
<p>EMAIL: <input type="text" name="address" size="20" /></p>
<input type="submit" name="submit" value="validate" />
</form>';
}
function validateEmail($address)
{
if(empty($address))
{
echo 'No Address Given';
return;
}
// This regex pattern lifted from user-notes at php.net
$domain = '([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)';
$atom = '[-a-z0-9!#$%&\'*+/=?^_`{|}~]';
$pattern = '^' . $atom . '+' . '(\.' . $atom . '+)*' . '@' . '(' . $domain . '{1,63}\.)+' . $domain . '{2,63}' . '$';
if(!eregi($pattern, $address))
{
echo 'Address Validation Failed!';
}
else
{
echo 'Address Is Valid!';
}
return;
}
Hope that helps.