Wrox Programmer Forums
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 27th, 2012, 12:58 PM
Registered User
 
Join Date: Jan 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to AfterAlot
Default email validation

please kindly show me how to validate email. i tried this

[ode]
if (!preg_match("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$", $_POST['email']))
{
echo 'Invalid email!';
header("Location:registration_feedback.php?msg=wro ng");
}
[code/]
 
Old December 3rd, 2012, 08:02 AM
Registered User
 
Join Date: Jul 2012
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Smile

You should try try this script which uses regular expressions to verify that a form field contains a legal email address.

Look here for some examples of legal email addresses that this script will identify:
• [email protected]
• [email protected]
• [email protected]
• [email protected]
• [email protected]
• [email protected]

Guide 1: Insert the underneath script to the <BODY> section of your web page:

Code:
<script type="text/javascript">

/***********************************************
* Email Validation script
* This notice must stay intact for legal use.
***********************************************/
var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
function checkmail(e){
var returnval=emailfilter.test(e.value)
if (returnval==false){
alert("Please enter a valid email address.")
e.select()
}
return returnval
}

</script>
<form>
<input name="myemail" type="text" style="width: 270px"> <input type="submit" onClick="return checkmail(this.form.myemail)" value="Submit" />
</form>
The code on top includes a example form where this script validates the email field contained. The form looks similar to this:

Code:
<form>
<input name="myemail" type="text" style="width: 300px"><br/>
<input type="submit" onClick="return checkmail(this.form.myemail)" value="Submit" />
</form>
To modify this script to serve up your own form, just change the parts in bold above to your own. More purposely, you first give your email address field a name(like name="myemail"). Then, adjust the submit button of the form by adding in the "onClick" part. keep in mind to alter "myemail" to replicate the name of your email address field.
 
Old April 30th, 2013, 04:51 AM
Registered User
 
Join Date: Dec 2012
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
Thumbs up

Validate the Email Address

$stremail=$_POST["txtemail"];
$result=ereg("^[^@ ]+@[^@ ]+\.[^@ ]+$",$stremail,$trashed);
if(!$result){
echo "Enter a valid E-mail Address";
DisplayForm();
}
else{
echo "Invalid E-mail Address";
$stremail="";
DisplayForm();
}

Try this code and check it. I am using this code for my email validation.
 
Old July 4th, 2013, 02:21 AM
Registered User
 
Join Date: Jul 2013
Posts: 11
Thanks: 0
Thanked 1 Time in 1 Post
Default

Simple regex:
Code:
return preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", $value);





Similar Threads
Thread Thread Starter Forum Replies Last Post
multiple email validation (different format) kumiko Javascript 2 July 22nd, 2008 08:06 AM
email validation function keyvanjan ASP.NET 1.0 and 1.1 Basics 3 August 17th, 2006 05:30 PM
Email validation problem mattastic Javascript How-To 1 May 19th, 2005 01:10 AM
Form validation and email checking visionary Beginning PHP 9 July 15th, 2003 01:06 PM
email validation tysta JSP Basics 3 June 23rd, 2003 12:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.