Hi Everyone,
I was hoping that someone can help me out. I made a form and want it to only make emails work in it (have to type blah@hotmail.com.) I am having issues with how to make it work. The code I have so far looks like this:
<div id="unsubscribe">
<form id="form" name="form" class="rt" method="post" action="">
<input type="hidden" name="source" value="flash games" />
<fieldset>
<label for="email1">
<span>Please enter your email address:</span>
<input type="text" name="email1" id="email1" />
</label>
<button class="submitBtn" name="button" id="button" type="submit"><span>Unsubscribe</span></button>
</fieldset>
</form>
</div>
Please let me know if any of you know the solution.
Thanks,
Reth
PHP Email Form Validation
Moderator: General Moderators
- The_Anomaly
- Forum Contributor
- Posts: 196
- Joined: Fri Aug 08, 2008 4:56 pm
- Location: Tirana, Albania
Re: PHP Email Form Validation
You have two options. Client-side validation (Javascript), or Server-side validation (PHP). The former can easily be bypassed, but is arguably easier to implement. The latter need to use REGEX, and can get a bit confusing.
Check this out.
Check this out.
- ironhamster88
- Forum Newbie
- Posts: 3
- Joined: Fri Oct 03, 2008 8:51 am
- Location: Essex, UK
Re: PHP Email Form Validation
this is a valid e-mail regex pattern.
hope it helps.
Code: Select all
$pattern = '/^[A-Z0-9._-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z.]{2,6}$/i';
if(preg_match($pattern, $_POST['email1'])) {
// email address is valid - send email, whatever
} else {
// incorrect email - display error message or something
}