Jump to content

Recommended Posts

[code]$regex = "^[A-Za-z0-9\._-]+@([A-Za-z0-9][A-Za-z0-9-]{1,62})(\.[A-Za-z][A-Za-z0-9-]{1,62})+$";[/code]
Make that a variable that can be accessed by the script
then pass this into the script
[code]if (!ereg("$regex", $_POST['email'])) { //tests emails format with regex variable above
$errorhandler .= "The email address is improperly formatted<br />";
}[/code]
The $_POST['email']
will be the name of your variable.
The errorhandler is what I use to record the errors but handle them however you want the important part is
if (!ereg( and the rest of it until )) {
That is the most important if the email is not formatted like
something@something.com
then it returns false/
Link to comment
https://forums.phpfreaks.com/topic/14180-php-form-validation/#findComment-55578
Share on other sites

[quote author=designationlocutus link=topic=100058.msg394458#msg394458 date=1152543082]
[quote author=Daniel0 link=topic=100058.msg394452#msg394452 date=1152542894]
In my opinion [url=http://php.net/preg_match]preg_match[/url] is better.
[/quote]
Hmm what are a major advantages over each?
[/quote]

I find preg_match faster and ereg is not binary-safe.
Link to comment
https://forums.phpfreaks.com/topic/14180-php-form-validation/#findComment-55583
Share on other sites

[quote author=Daniel0 link=topic=100058.msg394463#msg394463 date=1152543403]
[quote author=designationlocutus link=topic=100058.msg394458#msg394458 date=1152543082]
[quote author=Daniel0 link=topic=100058.msg394452#msg394452 date=1152542894]
In my opinion [url=http://php.net/preg_match]preg_match[/url] is better.
[/quote]
Hmm what are a major advantages over each?
[/quote]

I find preg_match faster and ereg is not binary-safe.
[/quote]

Hmm might have to give both functions a whizz and give them some difficult data to play with :) Thanks for the answer.
Link to comment
https://forums.phpfreaks.com/topic/14180-php-form-validation/#findComment-55585
Share on other sites

Preg match or ereg can be used interchangeably, it just has different syntax rules, one is based on Perl regular expressions hte other is based on post ix(?) I think it is
One is better than the other, pregmatch statistically is better and has more performance.
But ereg is good for small things, like checking emails, or whatever, and I think pregmatch has slightly harder to understand syntax, but it's better overall, atleast by what I have studied
Link to comment
https://forums.phpfreaks.com/topic/14180-php-form-validation/#findComment-55592
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.