note 102540 added to function.filter-var

[email protected] Sun, 20 Feb 2011 05:43:32 -0800
Newsgroups php.notes
Message-ID <[email protected]>
This is what I would call a "full email check".
This wont check if the domain is a valid email sender, but it does check if it's a valid domain. It also check every possible flaw of the email address, from length to the most unbelieveable character. I will use this for my CMS (Sourceforge: so44), hope someone find this useful.

Please take not of the Copyright. I've added a little note of it at the bottom to show that the PHP group has also modified this regex.

<?php

/*

	Valid Email
	
	Please add a note that Sondre B. Aasen [ [email protected] ] wrote this function

*/

function ve($veEmail) {
	if(strlen($veEmail) > 320) {
		return FALSE;
	}
	
	/*
		The following regex is under this copyright:
		
		Copyright © Michael Rushton 2009-2010
		http://squiloople.com/
		
		The regex has been modified by: Derick Rethans and Pierre-A. Joye (The PHP Group)
	*/
	
	// Remove all the line breaks from the regex, I had to add them because of a posting issue here on php.net
	if(!preg_match("/^(?!(?:

(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|

(?:\\x22?[^\\x5C\\x22]\\x22?))

{255,})(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)

|(?:\\x22?[^\\x5C\\x22]\\x22?)){65,}@)

(?:(?:[\\x21\\x23-\\x27\\x2A

\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)

|(?:\\x22(?:[\\x01-\\x08\\x0B

\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]

|(?:\\x5C[\\x00-\\x7F]))*\\x22))

(?:\\.(?:(?:[\\x21\\x23-\\x27\\x2A

\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)

|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C

\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|

(?:\\x5C[\\x00-\\x7F]))*\\x22)))*@

(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?

[a-z0-9]+(?:-[a-z0-9]+)*\\.)

{1,126}){1,}(?:(?:[a-z][a-z0-9]*)

|(?:(?:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)

|(?:\\[(?:(?:IPv6:(?:(?:[a-f0-9]

{1,4}(?::[a-f0-9]{1,4}){7})|

(?:(?!(?:.*[a-f0-9]

[:\\]]){7,})(?:[a-f0-9]{1,4}

(?::[a-f0-9]{1,4})

{0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]

{1,4}){0,5})?)))

|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]

{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})

(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4})

{0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]

{1,4}){0,3}:)?)))?(?:(?:25[0-5])

|(?:2[0-4][0-9])

|(?:1[0-9]{2})|(?:[1-9]?[0-9]))

(?:\\.(?:(?:25[0-5])

|(?:2[0-4][0-9])|(?:1[0-9]

{2})|(?:[1-9]?[0-9])))

{3}))\\]))$/iD", $veEmail)) {
		return FALSE;
	}
		
	if(!function_exists("checkdnsrr")) {
		exec("nslookup -type=ANY ".end(explode("@", $veEmail)), $matches);
		foreach($matches as $match) {
			if(preg_match("`^".end(explode("@", $veEmail))."`i", $match)) {
				return TRUE;
			}
		}
		
		return FALSE;
	}
	elseif(!checkdnsrr(end(explode("@", $veEmail)), "ANY")) {
		return FALSE;
	}
		
	return TRUE;
}

?>
----
Server IP: 85.19.212.230
Probable Submitter: 62.16.216.39
----
Manual Page -- http://www.php.net/manual/en/function.filter-var.php
Edit        -- https://master.php.net/note/edit/102540
Del: integrated  -- https://master.php.net/note/delete/102540/integrated
Del: useless     -- https://master.php.net/note/delete/102540/useless
Del: bad code    -- https://master.php.net/note/delete/102540/bad+code
Del: spam        -- https://master.php.net/note/delete/102540/spam
Del: non-english -- https://master.php.net/note/delete/102540/non-english
Del: in docs     -- https://master.php.net/note/delete/102540/in+docs
Del: other reasons-- https://master.php.net/note/delete/102540
Reject      -- https://master.php.net/note/reject/102540
Search      -- https://master.php.net/manage/user-notes.php