Ok, I have this PHP set up to take a name and email address and write it to a text file. It works great. However, I'd like to have it check to make sure its not an empty form (or better yet, maybe check to make sure there is a "@" somewhere in there) before it allows them to proceed.
Any hints?
Here's what I have now..
<?
if($Submit) //check for form submission
{
//compile the information to store within the textfile
$str_tofile = "name: $name\n";
$str_tofile.= "emailaddress: $emailaddress\n";
//open a file pointer to the text file where you want to save the submitted form data
$filepointer = fopen('maillist.txt','a+');
//save the submitted form data to the file
fwrite($filepointer,$str_tofile);
//thank the user
echo ?>blablabla
<form name="form1" method="post" action="maillist.php">
<table width="346" height="110" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>Name</td>
<td><input name="name" type="text" id="name"></td>
</tr>
<tr>
<td>Email Address</td>
<td><input name="emailaddress" type="text" id="emailaddress"></td>
</tr>
Checking an email FORM
Moderator: General Moderators
- daven
- Forum Contributor
- Posts: 332
- Joined: Tue Dec 17, 2002 1:29 pm
- Location: Gaithersburg, MD
- Contact:
Check out validateEmailFormat from Killersoft http://www.killersoft.com/downloads/paf ... on=viewall
This will check for an "@" and, after the "@", at least one "." but no more than two "." I have been told that you can have more than two "." after the "@" - although I've never seen that.
I've seen whole classes devoted to email validation using regex'ing and sometimes also checking for valid domains.
Can anyone tell me why you'd want to regex? Since special characters are used in email addresses, surely you have to allow them all, using something nice and simple similar to the above code.
Code: Select all
$domain = strstr($email, '@');
IF (!strstr($email, '@') OR substr_count($domain, ".") == 0 OR substr_count($domain, ".") > 2) { ..etcCan anyone tell me why you'd want to regex? Since special characters are used in email addresses, surely you have to allow them all, using something nice and simple similar to the above code.
Last edited by McGruff on Thu Aug 11, 2005 1:15 pm, edited 1 time in total.
- daven
- Forum Contributor
- Posts: 332
- Joined: Tue Dec 17, 2002 1:29 pm
- Location: Gaithersburg, MD
- Contact:
regex use in email validation is useful to ensure that the email: A) has a valid pattern (address@place.ext, add.re.ss@place.ext.loc, etc); and B) does not contain illegal characters. For example: name@place.org is fine, but name@place@site.org is not.