Code: Select all
<?if($_POST) {if($_POST[email]=="") {echo 'Please enter an email';} elseif(!eregi("^[[]][a-z0-9_.-] @[a-z0-9.-]+\.[a-z]{2,4}$", $email)) {echo "Not a valid email address\n";} else {$_SESSION[OK]++;}}?>Moderator: General Moderators
Code: Select all
<?if($_POST) {if($_POST[email]=="") {echo 'Please enter an email';} elseif(!eregi("^[[]][a-z0-9_.-] @[a-z0-9.-]+\.[a-z]{2,4}$", $email)) {echo "Not a valid email address\n";} else {$_SESSION[OK]++;}}?>Code: Select all
echo $arr['abc'];
echo $arr[2];
echo "xyz $arr[abc] zyx";Code: Select all
if( !isset($_POST['email']) || ''===$_POST['email']) {
echo 'Please enter an email';
}
else if { preg_match($pattern, $email) ) {
echo 'invalid email address';
}
else {
echo 'email address ok';
$_SESSION['OK']++;
}Code: Select all
/**
* Tests if the input matches a the basic syntaxical rules of an email address
*
* @return bool
*/
function isEmail($value)
{
return (bool)preg_match('/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/iu', $value);
}
/**
* Get a value or default if it is unavailable
*
* @param string|int $index of $source
* @param mixed $default if $source[$index] is blank or null
* @param array|null $source of data, null uses $_POST
* @return mixed
*/
function getVar($index, $default = '', $source = null)
{
if ($source === null) {
$source = $_POST;
}
if (isset($source[$index]) && !ctype_space($source[$index])) {
return trim($source[$index]);
} else {
return $default;
}
}
/**
* Generate an unordered HTML list
*
* @param mixed $data to use a list items
* @return string
*/
function htmlList($data)
{
if (empty($data)) {
return '';
}
return '<ul><li>' . implode('</li><li>', (array)$errors) . '</li></ul>';
}
/**
* Example Usage
*/
if (!empty($_POST)) {
$errors = array();
$email = getVar('email');
if (!isEmail($email)) {
$errors[] = 'Unspecified or invalid email address';
}
echo htmlList($errors);
}read this:darkfreaks wrote:i think i will use eregi
Happy holidaysphp.net wrote:Note: preg_match(), which uses a Perl-compatible regular expression syntax, is often a faster alternative to ereg().
http://de2.php.net/manual/en/ref.regex.php wrote:Tip: PHP also supports regular expressions using a Perl-compatible syntax using the PCRE functions. Those functions support non-greedy matching, assertions, conditional subpatterns, and a number of other features not supported by the POSIX-extended regular expression syntax.
http://de2.php.net/manual/en/ref.regex.php wrote:These regular expression functions are not binary-safe. The PCRE functions are.
pcre uses delimiters to separate the actual pattern from the options.darkfreaks wrote:i think i will use eregi if i use pregmatch i get the following error:
any ideas on how to fix this?Warning: preg_match() [function.preg-match]: No ending delimiter '^' found in /home/darkfrea/public_html/order.php on line 94
Code: Select all
<? if( !isset($_POST['email']) || ''===$_POST['email']) {echo 'Please enter an email';} else if (preg_match("'/^([-\w]+)(\.[-\w]+)*@([-a-z0-9]+\.?)+\.[a-z]{2,4}$/i'", $email)){echo 'invalid email address';} else { $_SESSION['OK']++; }}?>Code: Select all
<? if( !isset($_POST['email']) || ''===$_POST['email']) {echo 'Please enter an email';} else if (preg_match("/^([a-zA-Z0-9])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/", $email))
{echo 'invalid email address';} else { $_SESSION['OK']++; }}?>Code: Select all
}else {Code: Select all
function updateEmail(linkId, value) {
var linkElement = document.getElementById(linkId);
while(linkElement.hasChildNodes() == true) {
linkElement.removeChild(linkElement.childNodes[0]);
}
var emailFilter = /^.+@.+\..{2,4}$/;
if (emailFilter.test(value)) {
link = document.createElement('a');
link.href = 'mailto:'+value;
link.appendChild(document.createTextNode('Link'));
link.style.color = 'blue';
linkElement.appendChild(link);
} else {
linkElement.appendChild(document.createTextNode('Link'));
linkElement.style.color = 'grey';
}
}Code: Select all
<div><input id="viewContactEmailAddress" type="text" name="viewContactEmailAddress" style="width: 88%;" onKeyUp="updateEmail('viewContactEmailLink', this.value)"> (<span id="viewContactEmailLink">Link</a></span>)</div>