Technical Discussion
  >> Web Design / HTML / Web hosting Forum


Register (or login) on our website and you will not see this ad.


These posts have been archived and can no longer be replied to or modified.
  Print Thread
Standard User deleted
(deleted) Wed 21-Oct-09 13:08:57
Print Post

Validate Email Address in Forms


[link to this post]
 
Hi,

I'm wondering if there's any open source code that would allow me to check email addressses. At the moment, I check the format using some php ie - if it's in the format [email protected] it assumes the email address is correct. Trouble is, I'm getting quite a few that are incorrectly typed. Is there free script or software that would allow me to have two boxes for email entry , compare them and if correct allow the form to be sent. In fact, it just occurred to me that I'd probably need all new code (php) to check name entry not empty and compare the format of the email address and also compare the two email entries. Do I make sense here?

Hopefully someone can understand my nonsensical description of what I'm after and may thanks for any help.
Standard User deleted
(deleted) Wed 21-Oct-09 15:22:08
Print Post

Re: Validate Email Address in Forms


[re: deleted] [link to this post]
 
This looks like it may be a useful link for what you are after.
Standard User cheshire_man
(committed) Wed 21-Oct-09 16:50:30
Print Post

Re: Validate Email Address in Forms


[re: deleted] [link to this post]
 
I use the following code, whether it's elegant or not I neither know or care, but it seems to work ok.

<!-- the Form code -->
<tr>
	<td align="right">Your Email Address&nbsp;</td>
	<td><input type="text" name="Email" value="<?php echo stripslashes($_POST["Email"]) ?>"
		size="80" id="email1"></td>
</tr>
<tr>
	<!-- start Check email address -->
	<td align="right"><em>Please confirm email</em>&nbsp;</td>
	<td><input type="text" name="Emailx" value="<?php echo stripslashes($_POST["Emailx"]) ?>"
		size="80" id="email2"></td>
</tr>
..
..
..
..
<!-- the Submit button -->
<td colspan="3" align="center">
	<input type="submit" value="Submit" onclick="return checkemailaddress()">&nbsp;&nbsp;
</td>


<!-- and in a pre-loaded javascript file  -->
function checkemailaddress()
{
	if ( document.getElementById('email1').value != document.getElementById('email2').value )
	{
		alert('Email addresses do not match');
		return false;
	}
	return true;
}


Hope this is helpful

Edit:
This is the PHP validation code I use

if (!ereg("^[A-Za-z0-9@'\._-]+$",$value)
 or strpos($value,"@") <= 1
 or (strlen($value) - strpos($value,"@")) <= 3)
 { $bad_entry[$field] = "B"; }


Tony

Edited by cheshire_man (Wed 21-Oct-09 16:53:40)


Register (or login) on our website and you will not see this ad.

Standard User Etchy
(committed) Wed 21-Oct-09 23:55:07
Print Post

Re: Validate Email Address in Forms


[re: deleted] [link to this post]
 
The only way I know of to check if an email address truely exists is to first do an mx look up to check that
a the domain exists
b there is actually an mx server defined in the records

Then knowing the mail server address initiate a connection to it using smtp. If the mail server gives a response other than Recipient ok you know that the email address was bogus.

But this is taking it to the extreme level obviously time will be involved doing all of the above.

Reading your message again perhaps I am confused as to what you are asking
Standard User deleted
(deleted) Thu 22-Oct-09 11:16:24
Print Post

Re: Validate Email Address in Forms


[re: Etchy] [link to this post]
 
I think he's after a script which validates that a string

1) follows the syntax rules for an e-mail address and
2) that it has been entered identically in two separate form fields.
Standard User cheshire_man
(committed) Thu 22-Oct-09 11:18:16
Print Post

Re: Validate Email Address in Forms


[re: deleted] [link to this post]
 
The code/script I posted does that for me.

Tony
Standard User deleted
(deleted) Thu 22-Oct-09 11:41:41
Print Post

Re: Validate Email Address in Forms


[re: cheshire_man] [link to this post]
 
Yes, I think that's the sort of code the OP was looking for.
  Print Thread

Jump to