| | |
preg match
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Aug 2008
Posts: 94
Reputation:
Solved Threads: 0
Hello all,
I am having a hard time trying to figure out why I can't get my code to successfully check my email address. It seems I can plug in anything and it won't give me an error.
This is my code for that line:
When I type in just letters and don't include @ it accepts it and moves me right along. It's supposed to stop me and tell me to enter a valid email address. Hmmmm...
Any help will be appreciated
~Amy
I am having a hard time trying to figure out why I can't get my code to successfully check my email address. It seems I can plug in anything and it won't give me an error.
This is my code for that line:
PHP Syntax (Toggle Plain Text)
<?php session_start(); if((!empty($_POST['email']) && (preg_match('/^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$/', $_POST['email']) <50))) { $email=$_POST['email']; $email=htmlspecialchars($email); $_SESSION['email'] = $email; } else { $errors[]= 'You forgot to enter a valid E-mail Address!'; } if (empty($errors)) { header ("Location:http://www.thisnextpage.php"); exit(); } if (!empty($errors) && is_array($errors)) { echo '<h1>Error!</h1> The following error(s) occured:<br/ >'; foreach ($errors as $msg) { echo " - $msg<br />\n"; } } ?>
When I type in just letters and don't include @ it accepts it and moves me right along. It's supposed to stop me and tell me to enter a valid email address. Hmmmm...
Any help will be appreciated

~Amy
why are comparing the preg_match to "<50". preg_match returns true or false. it will return a matches array that you can get the count of if you are trying to make sure there are not over 50 email addresses in the field, which is probably not what you are trying to do.
just remove that and it should work. i didn't check out the rest of the code though, so I can't tell for sure.
just remove that and it should work. i didn't check out the rest of the code though, so I can't tell for sure.
Hi...
Why are u comparing this value with 50....
preg_match returns true of false...
If you are comparing with the strlength, then use different if for comparing the string length..
use the following if condition..
this will run...
Why are u comparing this value with 50....
preg_match returns true of false...
If you are comparing with the strlength, then use different if for comparing the string length..
use the following if condition..
this will run...
php Syntax (Toggle Plain Text)
if( !empty($_POST['email']) && preg_match('/^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$/', $_POST['email']) )
![]() |
Similar Threads
- help with preg match (PHP)
- help with preg match (PHP)
- Search for a string in a variable--- (PHP)
Other Threads in the PHP Forum
- Previous Thread: email configuration
- Next Thread: php limitations
| Thread Tools | Search this Thread |
5.2.10 action apache api array basic beginner binary broken cakephp checkbox class classes cms code computing confirm cron curl database date delete destroy display domain dynamic echo echo$_get[x]changingitintovariable... email error fatalerror file files folder form forms function functions google header href htaccess html iframe image include indentedsubcategory insert ip javascript joomla limit link load local login mail malfunction menu mlm mod_rewrite multiple mysql mysqlquery neutrality oop paypal pdf php query radio random record reference remote return script search server sessions sockets source space sql syntax system table thesishelp tutorial unset update upload url validation validator variable video web window.onbeforeunload=closeme; youtube






