Check Valid emailadres

Geschreven door Kevin van der Peet. Posted in Code snippets

 

function checkEmail($email) 
{
   // Create the syntactical validation regular expression
   $regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$";

   // Presume that the email is invalid
   $valid = 0;

   // Validate the syntax
   if (eregi($regexp, $email))
   {
      list($username,$domaintld) = split("@",$email);
      // Validate the domain
      if (getmxrr($domaintld,$mxrecords))
         $valid = 1;
   } else {
      $valid = 0;
   }

   return $valid;

}

 

.

Browser detecteren

Geschreven door Kevin van der Peet. Posted in Code snippets

Detecteerd de browser en browserversie.

// Browser detection

// Internet Explorer
var ie  = document.all != null;  //ie4 and above
var ie5 = document.getElementById && document.all;
var ie6 = document.getElementById && document.all&&(navigator.appVersion.indexOf("MSIE 6.")>=0);

// Netscape
var ns4 = document.layers != null;
var ns6 = document.getElementById && !document.all;
var ns  = ns4 || ns6;

// Firefox
var ff  = !document.layers && !document.all;

// Opera
var op  = navigator.userAgent.indexOf("opera")>0;
var op7 = op && operaVersion() <= 7;
var op8 = op && operaVersion() >= 8;

// Detects the Opera version
function operaVersion() {
	agent = navigator.userAgent;
	idx = agent.indexOf("opera");	
	if (idx>-1) {
		return parseInt(agent.subString(idx+6,idx+7));
	}
}

.

DIV centreren horizontaal en vertikaal

Geschreven door Kevin van der Peet. Posted in Code snippets

Centreer een DIV in het midden van het scherm.

body 
	{
	margin: 0px
	}

#horizon        
	{
	color: white;
	background-color: #0ff;
	text-align: center;
	position: absolute;
	top: 50%;
	left: 0px;
	width: 100%;
	height: 1px;
	overflow: visible;
	visibility: visible;
	display: block
	}

#content    
	{
	position: absolute;
	left: 50%;
	width: 250px; /* Overall width of div */
	height: 70px; /* Overall height of div */
	top: -35px; /* half of the overall height */
        margin-left: -125px; /* half of the overall width */
        visibility: visible
	}

.

Browser CSS hacks

Geschreven door Kevin van der Peet. Posted in Code snippets

/***** Selector Hacks ******/
 
/* IE6 and below */
* html #uno  { color: red }
 
/* IE7 */
*:first-child+html #dos { color: red } 
 
/* IE7, FF, Saf, Opera  */
html>body #tres { color: red }
 
/* IE8, FF, Saf, Opera (Everything but IE 6,7) */
html>/**/body #cuatro { color: red }
.

Detecteren van Iphone op browser

Geschreven door Kevin van der Peet. Posted in Code snippets

 

<?

function is_iPhone($agent='') {
    if(empty($agent)) $agent = $_SERVER['HTTP_USER_AGENT'];
    if(!empty($agent) and preg_match("~Mozilla/[^ ]+ \((iPhone|iPod); U; CPU [^;]+ Mac OS X; [^)]+\) AppleWebKit/[^ ]+ \(KHTML, like Gecko\) Version/[^ ]+ Mobile/[^ ]+ Safari/[^ ]+~",$agent,$match)) {
        return "YES";
    } elseif(stristr($agent,'iphone') or stristr($agent,'ipod')){
        return "MAYBE";
    } else {
        return "NO";
    }
}

echo is_iPhone();
?>

 

.