| | |
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 |
action address advanced ajax apache api array auto autoincrement basics beginner broken cakephp class classes cms code codingproblem combobox cron curl database date datepart domain dynamic email error errorlog file folder form format forms function functions google head href htaccess html image include includingmysecondfileinthechain interactive ip javascript job joomla js limit link load login malfunctioning masterthesis menu multiple mysql nodes oop outofmemmory paging password paypal pdf php popup problem procedure query ram random reference script search server sessions smarty source space sql stored syntax system table traffic tutorial unicode unset up-to-date upload url validation variable video web webapplications websitecontactform youtube






