Astuces Développeur Multimédia

Aller au contenu | Aller au menu | Aller à la recherche

mercredi 5 septembre 2007

Valider la syntaxe d'une adresse mail

Validation adresse mail

var _validator = new EmailValidator();			
_validator.validate(object_champ.text);
class EmailValidator extends String {						
	/*					
	Requires:	ActionScript v. 2.0				
	Date:		April 25, 2006			
	Contact:	admin@flashmx.us				
	Created by:	Nikolay Shishenkov				
	==============================					
	Idea: this class has 1 goal to allow you to verify email address string by basic email characteristics					
	it is based on the email standards information that can be found here:					
	http://www.remote.org/jochen/mail/info/chars.html					
	==============================					
	Usage:					
	//=> |START| copy from this line					
	//={ Boolean => email_validator.validate(String); }=					
	//Import class - in this example the class is located ubder the folder "classes" (relative to the project's FLA location)					
	import classes.EmailValidator;					
	//Create the validator object:					
	var email_validator	= new EmailValidator();				
	trace(email_validator.validate("admin@flashmx.us"));		// will return true			
	trace(email_validator.validate("admin#@flashmx.us"));		// will return false - because the string contains invalid character(#)			
	trace(email_validator.validate("admin@flashmx.tooLong"));	// will return false - because the domain name is invalid				
	//... basicly it will return true ONLY if the email is complaint to the standard email address requirements					
	//= final line to copy =| END |					
	*/					
	var ASCII_ALLOWED:Array	= [[38,39],[42,43],[45,57],[61,61],[63,63],[65,90],[94,95],[97,123],[125,126]];				
	//The list of all allowed ASCII Chars ranges for standard email address					
	//(including some special chars that are allowed in some cases such as {'}` etc.)					
	var i:Number, j:Number, email_arr:Array, after_arr:Array, str_len:Number;					
	//					
	function validate(inputString:String):Boolean{					
		//				
		if(inputString.length<1)return false;				
		//@				
		email_arr	= inputString.split("@");			
		if(email_arr.length!=2) return false; //	Only one @ is allowed			
		//.				
						
		//trace("after_arr "+after_arr);				
						
		var after_arr = email_arr[1].split(".");				
						
		if(after_arr == undefined)				
			return false;			
						
		if(after_arr[after_arr.length-1].length<2 || after_arr[after_arr.length-1].length>4)				
			return false; //	Only one . is allowed and after the . you can have between 2 and 4 chars		
		//				
		if(!ValidateString(email_arr[0].toString())||!ValidateString(email_arr[1].toString()))				
			return false;	// the email contains invalid characters		
		//				
		return true;	// this is a valid email			
	}					
	//					
	function ValidateString(_str:String):Boolean{					
		str_len	= _str.length;			
		//				
		for(i=0;i=ASCII_ALLOWED[j][0] && _chr<=ASCII_ALLOWED[j][1])			
				return true;	// the caracter falls into one of the allowed areas	
		//				
		return false;	// The used character is not allowed.			
	}					
}

Valider la syntaxe d'un code postal

Valider la syntaxe d'un code postal

function is_code_postal(zone){
	var code_postal = "0123456789";
	var resultat = true;
	
	if(zone.length < 5)
	return false;
	
	for (rang=0; rang<zone.length; rang++) {
	var chaine = zone.charAt(rang);
	trace("Chaine ! "+chaine+ " code_postal "+code_postal);
		if (code_postal.indexOf(chaine) == -1) {
			resultat = false;
			break;
		}
	}
	trace("res: "+resultat);
	return resultat;
}

Google analytics

Google analytics

Essayer le

Ajouter un "site map" à votre site

Un site map pour mieux être vu par les moteurs

xml-sitemaps.com

Téléchargement automatique de fichier

Téléchargement automatique de fichier

<?php
$Fichier_a_telecharger = 'NOM_FICHIER';
$chemin = '/';
$str = substr(strrchr($Fichier_a_telecharger, "/"),1);
$tailleFichier = filesize($Fichier_a_telecharger);
 
// on essaie de reconnaitre l'extension pour que le téléchargement corresponde au type de fichier afin d'éviter les erreurs de corruptions
switch(strrchr(basename($str), ".")) {
	case ".gz": $type = "application/x-gzip"; break;
	case ".tgz": $type = "application/x-gzip"; break;
	case ".zip": $type = "application/zip"; break;
	case ".rar": $type = "application/rar"; break;
	case ".pdf": $type = "application/pdf"; break;
	case ".png": $type = "image/png"; break;
	case ".gif": $type = "image/gif"; break;
	case ".jpeg": $type = "image/jpeg"; break;
	case ".jpg": $type = "image/jpg"; break;
	case ".txt": $type = "text/plain"; break;
	case ".htm": $type = "text/html"; break;
	case ".html": $type = "text/html"; break;
	default: $type = "application/octet-stream"; break;
}
 
header("Content-disposition: attachment; filename=$str");
header("Content-Type: application/force-download");
header("Content-Transfer-Encoding: $type\n"); // Surtout ne pas enlever le \n
header("Content-Length: ".$tailleFichier);
header("Pragma: no-cache");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0, public");
header("Expires: 0");
 
readfile($Fichier_a_telecharger);
?>

foreach() - recupération de variables

foreach() - Créer des variables à partir d'un tableau (dans l'exemple j'utilise $_GET[])

<?php
$be_var = $_GET;
 
foreach ( $be_var as $key => $value ) {
	$$key = $value;
	//$be_var = $be_var."&".$key."=".$value;
}
?>