<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog.Falci.me</title>
	<atom:link href="http://blog.falci.me/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.falci.me</link>
	<description></description>
	<lastBuildDate>Sun, 05 Jun 2011 00:11:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Funções Javascript para validações comuns</title>
		<link>http://blog.falci.me/javascript/funcoes-javascript-para-validacoes-comuns/</link>
		<comments>http://blog.falci.me/javascript/funcoes-javascript-para-validacoes-comuns/#comments</comments>
		<pubDate>Sun, 05 Jun 2011 00:10:51 +0000</pubDate>
		<dc:creator>Falci</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[dicas]]></category>
		<category><![CDATA[validações]]></category>

		<guid isPermaLink="false">http://blog.falci.me/?p=355</guid>
		<description><![CDATA[Este post contém alguns códigos javascript que juntei com o tempo. São validações e expressões regulares que as vezes precisamos em nosso sistemas. Validar Datas Uma ER para validar datas, no formato &#8220;d/m/Y&#8221;. Valida inclusive o 29 de fevereiro. Validar Telefone Validar Email Validar CPF Validar CNPJ Validar Inscrição Estadual Cada estado possui uma validação [...]]]></description>
			<content:encoded><![CDATA[<p>Este post contém alguns códigos javascript que juntei com o tempo. São validações e expressões regulares que as vezes precisamos em nosso sistemas.<span id="more-355"></span></p>
<h2>Validar Datas</h2>
<p>Uma ER para validar datas, no formato &#8220;d/m/Y&#8221;. Valida inclusive o 29 de fevereiro.</p>
<pre class="brush: jscript; title: ; notranslate">function validarData(data){
 return /^((([0][1-9]|[12][0-9])\/02\/(19|20)([13579][26]|[02468][048]))|(([0][1-9]|[1][0-9]|[2][0-8])\/02\/(19|20)([02468][12356]|[013579][13579]))|((([0][1-9]|[12][0-9]|30)\/(0[469]|11)|([0][1-9]|[12][0-9]|3[01])\/(0[13578]|1[02]))\/(19|20)[0-9][0-9]))$/.test(data);}// uso:if(!validarData('29/02/2016')){ alert('Data inválida');
 }</pre>
<h2>Validar Telefone</h2>
<pre class="brush: jscript; title: ; notranslate">function validarFone(fone){
 return /^\(?\d{2}\)? ?\d{4}\-?\d{4}$/.test(fone);
}</pre>
<h2>Validar Email</h2>
<pre class="brush: jscript; title: ; notranslate">function validarEmail(email){
	return /^[a-z0-9][a-z0-9\._-]+@[a-z0-9][a-z0-9\._-]+\.[a-z0-9]{2,6}(\.[a-z0-9]{2,6})?/i.test(email);
}</pre>
<h2>Validar CPF</h2>
<pre class="brush: jscript; title: ; notranslate">function validarCPF (cpf) {
	if (cpf.length != 11 || cpf == &quot;00000000000&quot; || cpf == &quot;11111111111&quot; || cpf == &quot;22222222222&quot; || cpf == &quot;33333333333&quot; || cpf == &quot;44444444444&quot; || cpf == &quot;55555555555&quot; || cpf == &quot;66666666666&quot; || cpf == &quot;77777777777&quot; || cpf == &quot;88888888888&quot; || cpf == &quot;99999999999&quot;)
	return false;

	add = 0;

	for (i=0; i &lt; 9; i ++)
		add += parseInt(cpf.charAt(i)) * (10 - i);

	rev = 11 - (add % 11);

	if (rev == 10 || rev == 11)
		rev = 0;

	if (rev != parseInt(cpf.charAt(9)))
		return false;

	add = 0;

	for (i = 0; i &lt; 10; i ++)
		add += parseInt(cpf.charAt(i)) * (11 - i);

	rev = 11 - (add % 11);

	if (rev == 10 || rev == 11)
		rev = 0;

	if (rev != parseInt(cpf.charAt(10)))
		return false;

	return true;
}</pre>
<h2>Validar CNPJ</h2>
<pre class="brush: jscript; title: ; notranslate">function validarCNPJ(cnpj){
	// DEIXA APENAS OS NÚMEROS
	cnpj = cnpj.replace('/','');
	cnpj = cnpj.replace('.','');
	cnpj = cnpj.replace('.','');
	cnpj = cnpj.replace('-','');

	var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;
	digitos_iguais = 1;

	if (cnpj.length &lt; 14 &amp;&amp; cnpj.length &lt; 15){
		return false;
	}
	for (i = 0; i &lt; cnpj.length - 1; i++){
		if (cnpj.charAt(i) != cnpj.charAt(i + 1)){
			digitos_iguais = 0;
			break;
		}
	}

	if (!digitos_iguais){
		tamanho = cnpj.length - 2
		numeros = cnpj.substring(0,tamanho);
		digitos = cnpj.substring(tamanho);
		soma = 0;
		pos = tamanho - 7;

		for (i = tamanho; i &gt;= 1; i--){
			soma += numeros.charAt(tamanho - i) * pos--;
			if (pos &lt; 2){
				pos = 9;
			}
		}
		resultado = soma % 11 &lt; 2 ? 0 : 11 - soma % 11;
		if (resultado != digitos.charAt(0)){
			return false;
		}
		tamanho = tamanho + 1;
		numeros = cnpj.substring(0,tamanho);
		soma = 0;
		pos = tamanho - 7;
		for (i = tamanho; i &gt;= 1; i--){
			soma += numeros.charAt(tamanho - i) * pos--;
			if (pos &lt; 2){
				pos = 9;
			}
		}
		resultado = soma % 11 &lt; 2 ? 0 : 11 - soma % 11;
		if (resultado != digitos.charAt(1)){
			return false;
		}
		return true;
	}else{
		return false;
	}
 }</pre>
<h2>Validar Inscrição Estadual</h2>
<p>Cada estado possui uma validação diferente, por isso o código ficou muito longo.</p>
<pre class="brush: jscript; collapse: true; light: false; title: ; toolbar: true; notranslate">

var OrdZero = '0'.charCodeAt(0);

function CharToInt(ch)
{
	return ch.charCodeAt(0) - OrdZero;
}

function IntToChar(intt)
{
	return String.fromCharCode(intt + OrdZero);
}

function CheckIEAC(ie){
	if (ie.length != 13)
		return false;
	var b = 4, soma = 0;

	for (var i = 0; i &lt;= 10; i++)
	{
		soma += CharToInt(ie.charAt(i)) * b;
		--b;
		if (b == 1) {
			b = 9;
		}
	}
	dig = 11 - (soma % 11);
	if (dig &gt;= 10) {
		dig = 0;
	}
	resultado = (IntToChar(dig) == ie.charAt(11));
	if (!resultado) {
		return false;
	}

	b = 5;
	soma = 0;
	for (var i = 0; i &lt;= 11; i++)
	{
		soma += CharToInt(ie.charAt(i)) * b;
		--b;
		if (b == 1) {
			b = 9;
		}
	}
	dig = 11 - (soma % 11);
	if (dig &gt;= 10) {
		dig = 0;
	}
	if (IntToChar(dig) == ie.charAt(12)) {
		return true;
	} else {
		return false;
	}
} //AC

function CheckIEAL(ie)
{
	if (ie.length != 9)
		return false;
	var b = 9, soma = 0;
	for (var i = 0; i &lt;= 7; i++)
	{
		soma += CharToInt(ie.charAt(i)) * b;
		--b;
	}
	soma *= 10;
	dig = soma - Math.floor(soma / 11) * 11;
	if (dig == 10) {
		dig = 0;
	}
	return (IntToChar(dig) == ie.charAt(8));
} //AL

function CheckIEAM(ie)
{
	if (ie.length != 9)
		return false;
	var b = 9, soma = 0;
	for (var i = 0; i &lt;= 7; i++)
	{
		soma += CharToInt(ie.charAt(i)) * b;
		b--;
	}
	if (soma &lt; 11) {
		dig = 11 - soma;
	}
	else {
		i = soma % 11;
		if (i &lt;= 1) {
			dig = 0;
		} else {
			dig = 11 - i;
		}
	}
	return (IntToChar(dig) == ie.charAt(8));
} //am

function CheckIEAP(ie)
{
	if (ie.length != 9)
		return false;
	var p = 0, d = 0, i = ie.substring(1, 8);
	if ((i &gt;= 3000001) &amp;&amp; (i &lt;= 3017000))
	{
		p =5;
		d = 0;
	}
	else if ((i &gt;= 3017001) &amp;&amp; (i &lt;= 3019022))
	{
		p = 9;
		d = 1;
	}
	b = 9;
	soma = p;
	for (var i = 0; i &lt;= 7; i++)
	{
		soma += CharToInt(ie.charAt(i)) * b;
		b--;
	}
	dig = 11 - (soma % 11);
	if (dig == 10)
	{
		dig = 0;
	}
	else if (dig == 11)
	{
		dig = d;
	}
	return (IntToChar(dig) == ie.charAt(8));
} //ap

function CheckIEBA(ie)
{
	if (ie.length != <img src='http://blog.falci.me/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' />
		return false;
	die = ie.substring(0, 8);
	var nro = new Array(8);
	var dig = -1;
	for (var i = 0; i &lt;= 7; i++)
	{
		nro[i] = CharToInt(die.charAt(i));
	}
	var NumMod = 0;
	if (String(nro[0]).match(/[0123458]/))
		NumMod = 10;
	else
		NumMod = 11;
	b = 7;
	soma = 0;
	for (i = 0; i &lt;= 5; i++)
	{
		soma += nro[i] * b;
		b--;
	}
	i = soma % NumMod;
	if (NumMod == 10)
	{
		if (i == 0) {
			dig = 0;
		} else {
			dig = NumMod - i;
		}
	}
	else
	{
		if (i &lt;= 1) {
			dig = 0;
		} else {
			dig = NumMod - i;
		}
	}
	resultado = (dig == nro[7]);
	if (!resultado) {
		return false;
	}
	b = 8;
	soma = 0;
	for (i = 0; i &lt;= 5; i++)
	{
		soma += nro[i] * b;
		b--;
	}
	soma += nro[7] * 2;
	i = soma % NumMod;
	if (NumMod == 10)
	{
		if (i == 0) {
			dig = 0;
		} else {
			dig = NumMod - i;
		}
	}
	else
	{
		if (i &lt;= 1) {
			dig = 0;
		} else {
			dig = NumMod - i;
		}
	}
	return (dig == nro[6]);
} //ba

function CheckIECE(ie)
{
	if (ie.length &gt; 9)
		return false;
	die = ie;
	if (ie.length &lt; 9)
	{
		while (die.length &lt;= <img src='http://blog.falci.me/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' />
			die = '0' + die;
	}
	var nro = Array(9);
	for (var i = 0; i &lt;= 8; i++)
		nro[i] = CharToInt(die[i]);
	b = 9;
	soma = 0;
	for (i = 0; i &lt;= 7; i++)
	{
		soma += nro[i] * b;
		b--;
	}
	dig = 11 - (soma % 11);
	if (dig &gt;= 10)
		dig = 0;
	return (dig == nro[8]);
} //ce

function CheckIEDF(ie)
{
	if (ie.length != 13)
		return false;
	var nro = new Array(13);
	for (var i = 0; i &lt;= 12; i++)
		nro[i] = CharToInt(ie.charAt(i));
	b = 4;
	soma = 0;
	for (i = 0; i &lt;= 10; i++)
	{
		soma += nro[i] * b;
		b--;
		if (b == 1)
			b = 9;
	}
	dig = 11 - (soma % 11);
	if (dig &gt;= 10)
		dig = 0;
	resultado = (dig == nro[11]);
	if (!resultado)
		return false;
	b = 5;
	soma = 0;
	for (i = 0; i &lt;= 11; i++)
	{
		soma += nro[i] * b;
		b--;
		if (b == 1)
			b = 9;
	}
	dig = 11 - (soma % 11);
	if (dig &gt;= 10)
		dig = 0;
	return (dig == nro[12]);
}
// CHRISTOPHE T. C. &lt;wG @ codingz.info&gt;
function CheckIEES(ie)
{
	if (ie.length != 9)
		return false;
	var nro = new Array(9);
	for (var i = 0; i &lt;= 8; i++)
		nro[i] = CharToInt(ie.charAt(i));
	b = 9;
	soma = 0;
	for (i = 0; i &lt;= 7; i++)
	{
		soma += nro[i] * b;
		b--;
	}
	i = soma % 11;
	if (i &lt; 2)
		dig = 0;
	else
		dig = 11 - i;
	return (dig == nro[8]);
}

function CheckIEGO(ie)
{
	if (ie.length != 9)
		return false;
	s = ie.substring(0, 2);
	if ((s == '10') || (s == '11') || (s == '15'))
	{
		var nro = new Array(9);
		for (var i = 0; i &lt;= 8; i++)
			nro[i] = CharToInt(ie.charAt(i));
		n = Math.floor(ie / 10);
		if (n = 11094402)
		{
			if ((nro[8] == 0) || (nro[8] == 1))
				return true;
		}
		b = 9;
		soma = 0;
		for (i = 0; i &lt;= 7; i++)
		{
			soma += nro[i] * b;
			b--;
		}
		i = soma % 11;
		if (i == 0)
			dig = 0;
		else
		{
			if (i == 1)
			{
				if ((n &gt;= 10103105) &amp;&amp; (n &lt;= 10119997))
					dig = 1;
				else
					dig = 0;
			}
			else
				dig = 11 - i;
		}
		return (dig == nro[8]);
	}
}

function CheckIEMA(ie)
{
	if (ie.length != 9)
		return false;
	var nro = new Array(9);
	for (var i = 0; i &lt;= 8; i++)
		nro[i] = CharToInt(ie.charAt(i));
	b = 9;
	soma = 0;
	for (i = 0; i &lt;= 7; i++)
	{
		soma += nro[i] * b;
		b--;
	}
	i = soma % 11;
	if (i &lt;= 1)
		dig = 0;
	else
		dig = 11 - i;
	return (dig == nro[8]);
}

function CheckIEMT(ie)
{
	if (ie.length &lt; 9)
		return false;
	die = ie;
	if (die.length &lt; 11)
	{
		while (die.length &lt;= 10)
			die = '0' + die;
		var nro = new Array(11);
		for (var i = 0; i &lt;= 10; i++)
			nro[i] = CharToInt(die[i]);
		b = 3;
		soma = 0;
		for (i = 0; i &lt;= 9; i++)
		{
			soma += nro[i] * b;
			b--;
			if (b == 1)
				b = 9;
		}
		i = soma % 11;
		if (i &lt;= 1)
			dig = 0;
		else
			dig = 11 - i;
		return (dig == nro[10]);
	}
} //muito

function CheckIEMS(ie)
{
	if (ie.length != 9)
		return false;
	if (ie.substring(0,2) != '28')
		return false;
	var nro = new Array(9);
	for (var i = 0; i &lt;= 8; i++)
		nro[i] = CharToInt(ie.charAt(i));
	b = 9;
	soma = 0;
	for (i = 0; i &lt;= 7; i++)
	{
		soma += nro[i] * b;
		b--;
	}
	i = soma % 11;
	if (i &lt;= 1)
		dig = 0;
	else
		dig = 11 - i;
	return (dig == nro[8]);
} //ms

function CheckIEPA(ie)
{
	if (ie.length != 9)
		return false;
	if (ie.substring(0, 2) != '15')
		return false;
	var nro = new Array(9);
	for (var i = 0; i &lt;= 8; i++)
		nro[i] = CharToInt(ie.charAt(i));
	b = 9;
	soma = 0;
	for (i = 0; i &lt;= 7; i++)
	{
		soma += nro[i] * b;
		b--;
	}
	i = soma % 11;
	if (i &lt;= 1)
		dig = 0;
	else
		dig = 11 - i;
	return (dig == nro[8]);
} //pra

function CheckIEPB(ie)
{
	if (ie.length != 9)
		return false;
	var nro = new Array(9);
	for (var i = 0; i &lt;= 8; i++)
		nro[i] = CharToInt(ie.charAt(i));
	b = 9;
	soma = 0;
	for (i = 0; i &lt;= 7; i++)
	{
		soma += nro[i] * b;
		b--;
	}
	i = soma % 11;
	if (i &lt;= 1)
		dig = 0;
	else
		dig = 11 - i;
	return (dig == nro[8]);
} //pb

function CheckIEPR(ie)
{
	if (ie.length != 10)
		return false;
	var nro = new Array(10);
	for (var i = 0; i &lt;= 9; i++)
		nro[i] = CharToInt(ie.charAt(i));
	b = 3;
	soma = 0;
	for (i = 0; i &lt;= 7; i++)
	{
		soma += nro[i] * b;
		b--;
		if (b == 1)
			b = 7;
	}
	i = soma % 11;
	if (i &lt;= 1)
		dig = 0;
	else
		dig = 11 - i;
	resultado = (dig == nro[8]);
	if (!resultado)
		return false;
	b = 4;
	soma = 0;
	for (i = 0; i &lt;= 8; i++)
	{
		soma += nro[i] * b;
		b--;
		if (b == 1)
			b = 7;
	}
	i = soma % 11;
	if (i &lt;= 1)
		dig = 0;
	else
		dig = 11 - i;
	return (dig == nro[9]);
} //pr

function CheckIEPE(ie)
{
	if (ie.length != 14)
		return false;
	var nro = new Array(14);
	for (var i = 0; i &lt;= 13; i++)
		nro[i] = CharToInt(ie.charAt(i));
	b = 5;
	soma = 0;
	for (i = 0; i &lt;= 12; i++)
	{
		soma += nro[i] * b;
		b--;
		if (b == 0)
			b = 9;
	}
	dig = 11 - (soma % 11);
	if (dig &gt; 9)
		dig = dig - 10;
	return (dig == nro[13]);
} //pe

function CheckIEPI(ie)
{
	if (ie.length != 9)
		return false;
	var nro = new Array(9);
	for (var i = 0; i &lt;= 8; i++)
		nro[i] = CharToInt(ie.charAt(i));
	b = 9;
	soma = 0;
	for (i = 0; i &lt;= 7; i++)
	{
		soma += nro[i] * b;
		b--;
	}
	i = soma % 11;
	if (i &lt;= 1)
		dig = 0;
	else
		dig = 11 - i;
	return (dig == nro[8]);
} //pi

function CheckIERJ(ie)
{
	if (ie.length != <img src='http://blog.falci.me/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' />
		return false;
	var nro = new Array(8);
	for (var i = 0; i &lt;= 7; i++)
		nro[i] = CharToInt(ie.charAt(i));
	b = 2;
	soma = 0;
	for (i = 0; i &lt;= 6; i++)
	{
		soma += nro[i] * b;
		b--;
		if (b == 1)
			b = 7;
	}
	i = soma % 11;
	if (i &lt;= 1)
		dig = 0;
	else
		dig = 11 - i;
	return (dig == nro[7]);
} //rj
// CHRISTOPHE T. C. &lt;wG @ codingz.info&gt;
function CheckIERN(ie)
{
	if (ie.length != 9)
		return false;
	var nro = new Array(9);
	for (var i = 0; i &lt;= 8; i++)
		nro[i] = CharToInt(ie.charAt(i));
	b = 9;
	soma = 0;
	for (i = 0; i &lt;= 7; i++)
	{
		soma += nro[i] * b;
		b--;
	}
	soma *= 10;
	dig = soma % 11;
	if (dig == 10)
		dig = 0;
	return (dig == nro[8]);
} //rn

function CheckIERS(ie)
{
	if (ie.length != 10)
		return false;
	i = ie.substring(0, 3);
	if ((i &gt;= 1) &amp;&amp; (i &lt;= 467))
	{
		var nro = new Array(10);
		for (var i = 0; i &lt;= 9; i++)
			nro[i] = CharToInt(ie.charAt(i));
		b = 2;
		soma = 0;
		for (i = 0; i &lt;= 8; i++)
		{
			soma += nro[i] * b;
			b--;
			if (b == 1)
				b = 9;
		}
		dig = 11 - (soma % 11);
		if (dig &gt;= 10)
			dig = 0;
		return (dig == nro[9]);
	} //if i&amp;&amp;i
} //rs

function CheckIEROantigo(ie)
{
	if (ie.length != 9) {
		return false;
	}

	var nro = new Array(9);
	b=6;
	soma =0;

	for( var i = 3; i &lt;= 8; i++) {

		nro[i] = CharToInt(ie.charAt(i));

		if( i != 8 ) {
			soma = soma + ( nro[i] * b );
			b--;
		}

	}

	dig = 11 - (soma % 11);
	if (dig &gt;= 10)
		dig = dig - 10;

	return (dig == nro[8]);

} //ro-antiga

function CheckIERO(ie)
{

	if (ie.length != 14) {
		return false;
	}

	var nro = new Array(14);
	b=6;
	soma=0;

	for(var i=0; i &lt;= 4; i++) {

		nro[i] = CharToInt(ie.charAt(i));

		soma = soma + ( nro[i] * b );
		b--;

	}

	b=9;
	for(var i=5; i &lt;= 13; i++) {

		nro[i] = CharToInt(ie.charAt(i));

		if ( i != 13 ) {
			soma = soma + ( nro[i] * b );
			b--;
		}

	}

	dig = 11 - ( soma % 11);

	if (dig &gt;= 10)
		dig = dig - 10;

	return(dig == nro[13]);

} //ro nova

function CheckIERR(ie)
{
	if (ie.length != 9)
		return false;
	if (ie.substring(0,2) != '24')
		return false;
	var nro = new Array(9);
	for (var i = 0; i &lt;= 8; i++)
		nro[i] = CharToInt(ie.charAt(i));
	var soma = 0;
	var n = 0;
	for (i = 0; i &lt;= 7; i++)
		soma += nro[i] * ++n;
	dig = soma % 9;
	return (dig == nro[8]);
} //rr

function CheckIESC(ie)
{
	if (ie.length != 9)
		return false;
	var nro = new Array(9);
	for (var i = 0; i &lt;= 8; i++)
		nro[i] = CharToInt(ie.charAt(i));
	b = 9;
	soma = 0;
	for (i = 0; i &lt;= 7; i++)
	{
		soma += nro[i] * b;
		b--;
	}
	i = soma % 11;
	if (i &lt;= 1)
		dig = 0;
	else
		dig = 11 - i;
	return (dig == nro[8]);
} //sc

// CHRISTOPHE T. C. &lt;wG @ codingz.info&gt;
function CheckIESP(ie)
{
	if (((ie.substring(0,1)).toUpperCase()) == 'P')
	{
		s = ie.substring(1, 9);
		var nro = new Array(12);
		for (var i = 0; i &lt;= 7; i++)
			nro[i] = CharToInt(s[i]);
		soma = (nro[0] * 1) + (nro[1] * 3) + (nro[2] * 4) + (nro[3] * 5) +
		(nro[4] * 6) + (nro[5] * 7) + (nro[6] * <img src='http://blog.falci.me/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> + (nro[7] * 10);
		dig = soma % 11;
		if (dig &gt;= 10)
			dig = 0;
		resultado = (dig == nro[8]);
		if (!resultado)
			return false;
	}
	else
	{
		if (ie.length &lt; 12)
			return false;
		var nro = new Array(12);
		for (var i = 0; i &lt;= 11; i++)
			nro[i] = CharToInt(ie.charAt(i));
		soma = (nro[0] * 1) + (nro[1] * 3) + (nro[2] * 4) + (nro[3] * 5) +
		(nro[4] * 6) + (nro[5] * 7) + (nro[6] * <img src='http://blog.falci.me/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> + (nro[7] * 10);
		dig = soma % 11;
		if (dig &gt;= 10)
			dig = 0;
		resultado = (dig == nro[8]);
		if (!resultado)
			return false;
		soma = (nro[0] * 3) + (nro[1] * 2) + (nro[2] * 10) + (nro[3] * 9) +
		(nro[4] * <img src='http://blog.falci.me/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> + (nro[5] * 7) + (nro[6] * 6)  + (nro[7] * 5) +
		(nro[8] * 4) + (nro[9] * 3) + (nro[10] * 2);
		dig = soma % 11;
		if (dig &gt;= 10)
			dig = 0;
		return (dig == nro[11]);
	}
} //sp

function CheckIESE(ie)
{
	if (ie.length != 9)
		return false;
	var nro = new Array(9);
	for (var i = 0; i &lt;= 8; i++)
		nro[i] = CharToInt(ie.charAt(i));
	b = 9;
	soma = 0;
	for (i = 0; i &lt;= 7; i++)
	{
		soma += nro[i] * b;
		b--;
	}
	dig = 11 - (soma % 11);
	if (dig &gt;= 10)
		dig = 0;
	return (dig == nro[8]);
} //se

function CheckIETO(ie)
{
	if (ie.length != 9) {
		return false;
	}

	var nro = new Array(9);
	b=9;
	soma=0;

	for (var i=0; i &lt;= 8; i++ ) {

		nro[i] = CharToInt(ie.charAt(i));

		if(i != <img src='http://blog.falci.me/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> {
			soma = soma + ( nro[i] * b );
			b--;
		}

	}

	ver = soma % 11;

	if ( ver &lt; 2 )

		dig=0;

	if ( ver &gt;= 2 )
		dig = 11 - ver;

	return(dig == nro[8]);
} //to

//inscrição estadual antiga
function CheckIETOantigo(ie)
{

	if ( ie.length != 11 ) {
		return false;

	}

	var nro = new Array(11);
	b=9;
	soma=0;

	s = ie.substring(2, 4);

	if( s != '01' || s != '02' || s != '03' || s != '99' ) {

		for ( var i=0; i &lt;= 10; i++)
		{

			nro[i] = CharToInt(ie.charAt(i));    

			if( i != 3 || i != 4) {

				soma = soma + ( nro[i] * b );
				b--;

			} // if ( i != 3 || i != 4 )

		} //fecha for

		resto = soma % 11;        

		if( resto &lt; 2 ) {    

			dig = 0;

		}

		if ( resto &gt;= 2 ) {

			dig = 11 - resto;

		}            

		return (dig == nro[10]);

	} // fecha if

}//fecha função CheckIETOantiga

function CheckIEMG(ie)
{
	if (ie.substring(0,2) == 'PR')
		return true;
	if (ie.substring(0,5) == 'ISENT')
		return true;
	if (ie.length != 13)
		return false;
	dig1 = ie.substring(11, 12);
	dig2 = ie.substring(12, 13);
	inscC = ie.substring(0, 3) + '0' + ie.substring(3, 11);
	insc=inscC.split('');
	npos = 11;
	i = 1;
	ptotal = 0;
	psoma = 0;
	while (npos &gt;= 0)
	{
		i++;
		psoma = CharToInt(insc[npos]) * i;
		if (psoma &gt;= 10)
			psoma -= 9;
		ptotal += psoma;
		if (i == 2)
			i = 0;
		npos--;
	}
	nresto = ptotal % 10;
	if (nresto == 0)
		nresto = 10;
	nresto = 10 - nresto;
	if (nresto != CharToInt(dig1))
		return false;
	npos = 11;
	i = 1;
	ptotal = 0;
	is=ie.split('');
	while (npos &gt;= 0)
	{
		i++;
		if (i == 12)
			i = 2;
		ptotal += CharToInt(is[npos]) * i;
		npos--;
	}
	nresto = ptotal % 11;
	if ((nresto == 0) || (nresto == 1))
		nresto = 11;
	nresto = 11 - nresto;
	return (nresto == CharToInt(dig2));
}

function CheckIE(ie, estado)
{
	ie = ie.replace(/\./g, '');
	ie = ie.replace(/\\/g, '');
	ie = ie.replace(/\-/g, '');
	ie = ie.replace(/\//g, '');
	if ( ie == 'ISENTO')
		return true;

	switch (estado)
	{
		case 'AC':
		case '1':
			return CheckIEAC(ie);
			break;
		case 'AL':
		case '2':
			return CheckIEAL(ie);
			break;
		case 'AM':
		case '3':
			return CheckIEAM(ie);
			break;
		case 'AP':
		case '4':
			return CheckIEAP(ie);
			break;
		case 'BA':
		case '5':
			return CheckIEBA(ie);
			break;
		case 'CE':
		case '6':
			return CheckIECE(ie);
			break;
		case 'DF':
		case '7':
			return CheckIEDF(ie);
			break;
		case 'ES':
		case '8':
			return CheckIEES(ie);
			break;
		case 'GO':
		case '9':
			return CheckIEGO(ie);
			break;
		case 'MA':
		case '10':
			return CheckIEMA(ie);
			break;
		case 'MG':
		case '11':
			return CheckIEMG(ie);
			break;
		case 'MS':
		case '12':
			return CheckIEMS(ie);
			break;
		case 'MT':
		case '13':
			return CheckIEMT(ie);
			break;
		case 'PA':
		case '14':
			return CheckIEPA(ie);
			break;
		case 'PB':
		case '15':
			return CheckIEPB(ie);
			break;
		case 'PE':
		case '16':
			return CheckIEPE(ie);
			break;
		case 'PI':
		case '17':
			return CheckIEPI(ie);
			break;
		case 'PR':
		case '18':
			return CheckIEPR(ie);
			break;
		case 'RJ':
		case '19':
			return CheckIERJ(ie);
			break;
		case 'RN':
		case '20':
			return CheckIERN(ie);
			break;
		case 'RO':
		case '21':
			return ((CheckIERO(ie)) || (CheckIEROantigo(ie)));
			break;
		case 'RR':
		case '22':
			return CheckIERR(ie);
			break;
		case 'RS':
		case '23':
			return CheckIERS(ie);
			break;
		case 'SC':
		case '24':
			return CheckIESC(ie);
			break;
		case 'SE':
		case '25':
			return CheckIESE(ie);
			break;
		case 'SP':
		case '26':
			return CheckIESP(ie);
			break;
		case 'TO':
		case '27':
			return ((CheckIETO(ie)) || (CheckIETOantigo(ie)));
			break;//return CheckIETO(ie); break;
	}
}</pre>
<p>Algumas vezes, o código javascript fica muito extenso. Uma solução é compactar o arquivo js. Esse site faz isso: <a title="Javascript Compressor" href="http://javascriptcompressor.com/" target="_blank">http://javascriptcompressor.com/</a><br /> Lembre-se de guardar o original para fazer alterações quando necessário.</p>
<p>Mas se precisar, também tem esse site: <a title="unPacker" href="http://matthewfl.com/unPacker.html" target="_blank">http://matthewfl.com/unPacker.html</a> que faz o efeito inverso, ou seja, descompacta.</p>
<blockquote><p>
Fonte:  tenho esses código há algum tempo, e infelizmente não sei quais são as fontes. Se você for autor de alguma dessas funções, entre em contato para resolvermos isso.
</p></blockquote>
<p>Faltou alguma função que acha interessante? Deixe um comentário!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.falci.me/javascript/funcoes-javascript-para-validacoes-comuns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parceiros da Estrada</title>
		<link>http://blog.falci.me/portfolio/parceiros-da-estrada/</link>
		<comments>http://blog.falci.me/portfolio/parceiros-da-estrada/#comments</comments>
		<pubDate>Tue, 31 May 2011 22:06:59 +0000</pubDate>
		<dc:creator>Falci</dc:creator>
				<category><![CDATA[Portfólio]]></category>

		<guid isPermaLink="false">http://blog.falci.me/?p=339</guid>
		<description><![CDATA[Descrição: Site desenvolvido sobre a plataforma WordPress para o &#8220;Parceiros da Estrada &#8211; Moto Clube&#8221;. O objetivo do site é exibir fotos e vídeos dos encontros e eventos o Moto Clube participa. Tecnologias: PHP, MySQL, CSS Link: www.parceirosdaestrada.com.br]]></description>
			<content:encoded><![CDATA[
<a href='http://blog.falci.me/portfolio/parceiros-da-estrada/attachment/pde1-2/' title='Página de fotos'><img width="140" height="140" src="http://blog.falci.me/wp-content/uploads/2011/05/pde11-140x140.jpg" class="attachment-thumbnail" alt="Página de fotos" title="Página de fotos" /></a>
<a href='http://blog.falci.me/portfolio/parceiros-da-estrada/attachment/pde2/' title='Página de Video'><img width="140" height="140" src="http://blog.falci.me/wp-content/uploads/2011/05/pde2-140x140.jpg" class="attachment-thumbnail" alt="Página de Video" title="Página de Video" /></a>
<a href='http://blog.falci.me/portfolio/parceiros-da-estrada/attachment/pde3/' title='Agenda de Eventos, Contador de Acessos e Visitantes Online e Arquivos do Site'><img width="140" height="140" src="http://blog.falci.me/wp-content/uploads/2011/05/pde3-140x140.jpg" class="attachment-thumbnail" alt="Agenda de Eventos, Contador de Acessos e Visitantes Online e Arquivos do Site" title="Agenda de Eventos, Contador de Acessos e Visitantes Online e Arquivos do Site" /></a>
<a href='http://blog.falci.me/portfolio/parceiros-da-estrada/attachment/pde4/' title='Tela de Login - WordPress'><img width="140" height="140" src="http://blog.falci.me/wp-content/uploads/2011/05/pde4-140x140.jpg" class="attachment-thumbnail" alt="Tela de Login - WordPress" title="Tela de Login - WordPress" /></a>

<p><strong>Descrição:</strong> Site desenvolvido sobre a plataforma  WordPress para o &#8220;Parceiros da Estrada &#8211; Moto Clube&#8221;. O objetivo do site é exibir fotos e vídeos dos encontros e eventos o Moto Clube participa.</p>
<p><strong>Tecnologias:</strong> PHP, MySQL, CSS</p>
<p><strong>Link:</strong> <a title="Parceiros da Estrada" href="http://www.parceirosdaestrada.com.br" target="_blank">www.parceirosdaestrada.com.br</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.falci.me/portfolio/parceiros-da-estrada/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Mobile &#8211; Tutorial Básico</title>
		<link>http://blog.falci.me/javascript/jquery-mobile-tutorial-basico/</link>
		<comments>http://blog.falci.me/javascript/jquery-mobile-tutorial-basico/#comments</comments>
		<pubDate>Tue, 05 Apr 2011 01:43:47 +0000</pubDate>
		<dc:creator>Falci</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[celular]]></category>
		<category><![CDATA[dispositivos móveis]]></category>
		<category><![CDATA[jQuery Mobile]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://blog.falci.me/?p=317</guid>
		<description><![CDATA[Como dipositivos móveis inteligêntes estão por toda parte, a necessidade de criar páginas web aumenta. Construir uma página web para celular é diferente em muitas maneira do que construir uma página web &#8220;normal&#8221;. Para nos ajudar, algumas pessoas desenvolveram um sistema de interface de usuário unificada para todas as plataformas populares de dispositivo móvel, construída [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.falci.me/wp-content/uploads/2011/04/print_iphone.png"><img class="alignleft size-medium wp-image-325" title="Exemplo no iPhone" src="http://blog.falci.me/wp-content/uploads/2011/04/print_iphone-158x300.png" alt="" width="158" height="300" /></a>Como dipositivos móveis inteligêntes estão por toda parte, a necessidade de criar páginas web aumenta.<br />
Construir uma página web para celular é diferente em muitas maneira do que construir uma página web &#8220;normal&#8221;.</p>
<p>Para nos ajudar, algumas pessoas desenvolveram um sistema de interface de usuário unificada para todas as plataformas populares de dispositivo móvel, construída sobre a rocha sólida do jQuery e jQuery UI. Sim, é o jQuery Mobile.</p>
<p>Então, deixe-me mostrar como é fácil usá-lo. Para começar a desenvolver com jQuery Mobile, a primeira coisa que você precisa é construir um modelo padronizado e ver se tudo está funcionando conforme o esperado.<span id="more-317"></span></p>
<p>Então abra seu editor favorito e digite o código:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
		&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot; /&gt;
    &lt;title&gt;jQuery Mobile  - Tutorial - Blog.Falci.me&lt;/title&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.css&quot; /&gt;
    &lt;script src=&quot;http://code.jquery.com/jquery-1.4.3.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.js&quot;&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;div data-role=&quot;page&quot;&gt;

    &lt;div data-role=&quot;header&quot;&gt;
        &lt;h1&gt;Título&lt;/h1&gt;
    &lt;/div&gt;&lt;!-- /header --&gt;

    &lt;div data-role=&quot;content&quot;&gt;
        &lt;p&gt;Conteúdo&lt;/p&gt;
    &lt;/div&gt;&lt;!-- /content --&gt;

    &lt;div data-role=&quot;footer&quot;&gt;
        &lt;h4&gt;Rodapé&lt;/h4&gt;
    &lt;/div&gt;&lt;!-- /footer --&gt;
&lt;/div&gt;&lt;!-- /page --&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Agora salve esta página como <span class="code">index.php</span> e abra no navegador. OMG, funciona! Como você pode ver, nós chamamos a jQuery, jQuery Mobile e também o CSS.</p>
<p>Se você olhar bem, vai ver alguns atributos estranhos como &#8220;data-role&#8221; (dados da função). São exatamente esses atributos que dizem ao jQuery Mobile o que esse elemento é, como procurar e como se comportar.</p>
<p>Então vamos fazer algo a mais. Existem dois tipos de ligação dentro jQuery Mobile: externo e interno. Deixe-me mostrar a mágica:</p>
<h2>Links externos</h2>
<p>Por padrão, quando você clica em um link que aponta para uma página externa (ex. produtos.php), o framework irá analisar href do link para formular uma solicitação do Ajax (Hijax) e exibe o botão &#8216;carregando&#8217;.</p>
<p>Se a solicitação do ajax é for bem sucedida, o conteúdo da nova página é adicionada ao DOM, todos os widgets móveis são auto-inicializado, então uma aninmação exibe a nova página.</p>
<p>Se o pedido ajax falhar, o framework vai mostrar uma pequena mensagem de erro, que desaparece depois de um breve período de tempo, de modo que este não interromper o fluxo de navegação.</p>
<p>Abra um novo arquivo e cole isto:</p>
<pre class="brush: xml; title: ; notranslate">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
		&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot; /&gt;
    &lt;title&gt;jQuery Mobile  - Tutorial - Blog.Falci.me&lt;/title&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.css&quot; /&gt;
    &lt;script src=&quot;http://code.jquery.com/jquery-1.4.3.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.js&quot;&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;div data-role=&quot;page&quot;&gt;

    &lt;div data-role=&quot;header&quot;&gt;
        &lt;h1&gt;Título&lt;/h1&gt;
    &lt;/div&gt;&lt;!-- /header --&gt;

    &lt;div data-role=&quot;content&quot;&gt;
        &lt;p&gt;Conteúdo&lt;/p&gt;
				&lt;p&gt;&lt;a href=&quot;index.php&quot;&gt;Clique aqui para mostrar a primeira página!&lt;/a&gt;&lt;/p&gt;
    &lt;/div&gt;&lt;!-- /content --&gt;

    &lt;div data-role=&quot;footer&quot;&gt;
        &lt;h4&gt;Rodapé&lt;/h4&gt;
    &lt;/div&gt;&lt;!-- /footer --&gt;
&lt;/div&gt;&lt;!-- /page --&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Salve este arquivo como <span class="code">produtos.php</span> e abra-o no navegador. Se você clicar no link, você irá ver uma mensagem &#8220;Carregando&#8221; e a nova página será carregada. Além disso, um botão Voltar será exibido no cabeçalho.</p>
<p>Se algo estiver errado (por exemplo, escreveu &#8220;ondex.php&#8221; no lugar de &#8220;index.php&#8221;), você receberá uma mensagem de erro.</p>
<h2>Links internos</h2>
<p>Um único documento HTML pode conter várias páginas que serão carregadas juntas, empilhando várias divs com um <span class="code">data-role=&#8221;page&#8221;</span>. Cada bloco <span class="code">page</span> precisa de um ID único (id=&#8221;primeira&#8221;) que será usado para ligar internamente as páginas (href=&#8221;#primeira&#8221;). Quando um link é clicado, o framework vai olhar para uma página interna com a identificação e irá fazer um efeito de transição.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!-- Inicio da primeira página --&gt;
&lt;div data-role=&quot;page&quot; id=&quot;primeira&quot;&gt;

    &lt;div data-role=&quot;header&quot;&gt;
        &lt;h1&gt;Primeira Página&lt;/h1&gt;
    &lt;/div&gt;&lt;!-- /header --&gt;

    &lt;div data-role=&quot;content&quot;&gt;
        &lt;p&gt;Conteúdo&lt;/p&gt;
        &lt;p&gt;Veja uma página interna chamada &lt;a href=&quot;#segunda&quot;&gt;Segunda&lt;/a&gt;&lt;/p&gt;
    &lt;/div&gt;&lt;!-- /content --&gt;

    &lt;div data-role=&quot;footer&quot;&gt;
        &lt;h4&gt;Rodapé da Página&lt;/h4&gt;
    &lt;/div&gt;&lt;!-- /footer --&gt;
&lt;/div&gt;&lt;!-- /page --&gt;

&lt;!-- Inicio da segunda página --&gt;
&lt;div data-role=&quot;page&quot; id=&quot;segunda&quot;&gt;

    &lt;div data-role=&quot;header&quot;&gt;
        &lt;h1&gt;Segunda Página&lt;/h1&gt;
    &lt;/div&gt;&lt;!-- /header --&gt;

    &lt;div data-role=&quot;content&quot;&gt;
        &lt;p&gt;Eu sou o segundo conteúdo&lt;/p&gt;
        &lt;p&gt;&lt;a href=&quot;#primeira&quot;&gt;Volte para a primeira página&lt;/a&gt;&lt;/p&gt;
    &lt;/div&gt;&lt;!-- /content --&gt;

    &lt;div data-role=&quot;footer&quot;&gt;
        &lt;h4&gt;Rodapé da Página&lt;/h4&gt;
    &lt;/div&gt;&lt;!-- /footer --&gt;
&lt;/div&gt;&lt;!-- /page --&gt;
</pre>
<p>O código acima deverá ser colocado dentro das tags body.</p>
<p>É importante lembrar, que se você está linkando de uma página carregada via ajax, para uma página com multiplas páginas internas, você precisa adicionar o <span class="code">rel=&#8221;external&#8221;</span> para o link. Isto diz ao framework para fazer um carregamento total para limpar o hash do ajax na URL. Isso é crítico porque as páginas as usam o hash (#) para rastrear o histórico do ajax enquanto multiplas páginas usam o hash para indicar uma página interna que haja um conflito.</p>
<h2>Temas</h2>
<p>Você pode facilmente usar qualquer tema no jQuery Mobile com o atributo <span class="code">data-theme</span> (dados do tema). Tente algo assim:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
		&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot; /&gt;
    &lt;title&gt;jQuery Mobile  - Tutorial - Blog.Falci.me&lt;/title&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.css&quot; /&gt;
    &lt;script src=&quot;http://code.jquery.com/jquery-1.4.3.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.js&quot;&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;div data-role=&quot;page&quot;&gt;

    &lt;div data-role=&quot;header&quot; data-theme=&quot;b&quot;&gt;
        &lt;h1&gt;Título&lt;/h1&gt;
    &lt;/div&gt;&lt;!-- /header --&gt;

    &lt;div data-role=&quot;content&quot; data-theme=&quot;b&quot;&gt;
        &lt;p&gt;Conteúdo&lt;/p&gt;
    &lt;/div&gt;&lt;!-- /content --&gt;

    &lt;div data-role=&quot;footer&quot; data-theme=&quot;b&quot;&gt;
        &lt;h4&gt;Rodapé&lt;/h4&gt;
    &lt;/div&gt;&lt;!-- /footer --&gt;
&lt;/div&gt;&lt;!-- /page --&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Experimente no seu navegador. Você deverá ver um tema azulado. Você pode tentar outras letras como E ou A.</p>
<p>Isso é tudo para o tutorial básico. Da próxima vez, vamos começar a construir a nossa página web de exemplo em jQuery Mobile a partir do zero. Espero que gostem dessa incrível peça de software e percebam o quão fácil é para começar.</p>
<blockquote><p>Traduzido e adaptado de <a title="CodeForest.net" href="http://www.codeforest.net/jquery-mobile-tutorial-basics" target="_blank">CodeForest.net</a></p></blockquote>
<p><a class="demo" href="http://blog.falci.me/exemplos/mobile.html" target="_blank"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.falci.me/javascript/jquery-mobile-tutorial-basico/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Visitantes Online</title>
		<link>http://blog.falci.me/mysql/visitantes-online/</link>
		<comments>http://blog.falci.me/mysql/visitantes-online/#comments</comments>
		<pubDate>Sun, 27 Mar 2011 14:32:35 +0000</pubDate>
		<dc:creator>Falci</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.falci.me/?p=301</guid>
		<description><![CDATA[Este post mostra como adicionar em seu site um contador de visitantes online (não necessárimente usuários logados), sem o uso de sites externos, apenas com PHP e MySQL. IP x SESSION Precisamos identificar o visitante para que ele não seja contado mais de uma vez no site. Podemos usar o IP ou a SESSION como [...]]]></description>
			<content:encoded><![CDATA[<p>Este post mostra como adicionar em seu site um contador de visitantes online (não necessárimente usuários logados), sem o uso de sites externos, apenas com PHP e MySQL.<span id="more-301"></span></p>
<h2>IP x SESSION</h2>
<p>Precisamos identificar o visitante para que ele não seja contado mais de uma vez no site.</p>
<p>Podemos usar o IP ou a SESSION como identificador do usuário. Porém ambas as opções tem um um problema de imprecisão:</p>
<p>Session: se um usuário usar dois browser diferentes, ele terá duas sessions distintas, logo contará como dois usuários online</p>
<p>IP: uma empresa ou mesmo uma lan house possuem um IP para a rede toda, e depois um IP interno para cada máquina. Ao acessar o site, o PHP consegue descobrir o IP externo. Então se houver vários visitantes dentro dessa rede (cada um em seu computador) o PHP vai ver apenas um IP.</p>
<p>Ou seja: a Session erra para mais, e o IP erra para menos.</p>
<p>Mesmo assim, a Session é mais precisa, pois só mostrará a mais se o visitante fizer algo fora do comum.</p>
<h2>Banco de Dados</h2>
<p>Depois de identificar o usuários, precisamos registrar no banco de dados a presença dele.</p>
<p>Segue abaixo o sql para criar a tabela:</p>
<pre class="brush: sql; title: ; notranslate">CREATE TABLE `online` (
`time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
`session` CHAR( 32 ) NOT NULL

)</pre>
<h2>PHP</h2>
<p>Agora vamos criar um arquivo php que será responsável por fazer o insert nessa tabela:</p>
<p><strong>online.php</strong></p>
<pre class="brush: php; title: ; notranslate">&lt;?php

// Conexão com o banco de dados
include_once &quot;conexao.php&quot;;

// Inicia a session
@session_start();

// pega o ID da session
$id = session_id();

// insere na tabela
mysql_query(&quot;INSERT INTO online (session) VALUES ('$id');&quot;);
// Obs.: não é preciso informar o time, pois o default é CURRENT_TIMESTAMP;</pre>
<p>Depois, no mesmo arquivo nós vamos excluir as sessions que foram geradas a mais de 10 minutos:</p>
<pre class="brush: php; title: ; notranslate">
// contar os usuários online nos ultimos...
$tempo = 10; // minutos

// em segundos:
$tempo = $tempo * 60;

// Deleta os registros que foram feitos a mais de &quot;$tempo&quot; minutos
mysql_query(&quot;DELETE FROM online WHERE time &lt; (NOW() - $tempo)&quot;);</pre>
<p>Agora só precisamos contar quantas sessions diferentes sobraram:</p>
<pre class="brush: php; title: ; notranslate">// Conta (count) quantas sessions diferentes (distinct) há na tabela
$query = mysql_query(&quot;SELECT COUNT( DISTINCT( session ) ) FROM online&quot;);

$online = mysql_result($query, 0);</pre>
<p>Pronto!</p>
<p>Faça include desse arquivo em todas as páginas do site. Você pode exibir a quantidade de usuários online com <span class="code">&lt;?php echo $online; ?&gt;</span></p>
<p>Código completo: <strong>online.php</strong></p>
<pre class="brush: php; title: ; notranslate">&lt;?php

// Conexão com o banco de dados
include_once &quot;conexao.php&quot;;

// Inicia a session
@session_start();

// pega o ID da session
$id = session_id();

// insere na tabela
mysql_query(&quot;INSERT INTO online (session) VALUES ('$id');&quot;);
// Obs.: não é preciso informar o time, pois o default é CURRENT_TIMESTAMP;

// contar os usuários online nos ultimos...
$tempo = 10; // minutos

// em segundos:
$tempo = $tempo * 60;

// Deleta os registros que foram feitos a mais de &quot;$tempo&quot; minutos
mysql_query(&quot;DELETE FROM online WHERE time &lt; (NOW() - $tempo)&quot;);

// Conta (count) quantas sessions diferentes (distinct) há na tabela
$query = mysql_query(&quot;SELECT COUNT( DISTINCT( session ) ) FROM online&quot;);

$online = mysql_result($query, 0);</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.falci.me/mysql/visitantes-online/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>De cara nova!</title>
		<link>http://blog.falci.me/bla-bla-bla/de-cara-nova/</link>
		<comments>http://blog.falci.me/bla-bla-bla/de-cara-nova/#comments</comments>
		<pubDate>Sat, 26 Mar 2011 16:16:38 +0000</pubDate>
		<dc:creator>Falci</dc:creator>
				<category><![CDATA[bla bla bla]]></category>

		<guid isPermaLink="false">http://blog.falci.me/?p=298</guid>
		<description><![CDATA[Hospedagem Resolvi mudar um pouco as coisas por aqui. Troquei o servidor, sai da Kinghost e agora estou na Locaweb. Não que lá seja ruim, longe disso (inclusive recomendo a Kinghost!), mas a Locaweb tem um plano interessante, onde eu posso fazer vários sites (até 100) tudo na mesma conta.. cada um em um diretório [...]]]></description>
			<content:encoded><![CDATA[<h2>Hospedagem</h2>
<p>Resolvi mudar um pouco as coisas por aqui. Troquei o servidor, sai da Kinghost e agora estou na Locaweb. Não que lá seja ruim, longe disso (inclusive recomendo a Kinghost!), mas a Locaweb tem um plano interessante, onde eu posso fazer vários sites (até 100)  tudo na mesma conta.. cada um em um diretório e no final fica transparente.</p>
<p>Achei essa opção ideal pra mim, pois pretendo fazer pequenos sites, para clientes que não tem servidor. Assim já mato o problema da hospedagem.</p>
<p>&nbsp;</p>
<h2>WordPress</h2>
<p>Há algum tempo já, que estou me dedicando mais ao WordPress (e menos ao PHP puro).. Estou gostando muito das facilidade e agilidade de desenvolver sites com ele. Pensando nisso, resolvi procurar um tema bacana, e fiz a página inicial do site dentro do blog (<a title="Abertura" href="http://blog.falci.me/abertura/">Abertura</a>). É só um menu simples, com ícones, mas me agradou bastante.</p>
<p>Alguns plugins ainda não foram instalados, outros foram substituidos.. aos poucos vou aperfeiçoando o blog.</p>
<p>Espero que gostem das novidades. Dúvidas, sugestões ou reclamações: entrem em contato, nos comentários ou pelo formulário.</p>
<p>Até a próxima <img src='http://blog.falci.me/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.falci.me/bla-bla-bla/de-cara-nova/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BDS Sistemas</title>
		<link>http://blog.falci.me/portfolio/bds-sistemas/</link>
		<comments>http://blog.falci.me/portfolio/bds-sistemas/#comments</comments>
		<pubDate>Fri, 25 Mar 2011 23:33:51 +0000</pubDate>
		<dc:creator>Falci</dc:creator>
				<category><![CDATA[Portfólio]]></category>

		<guid isPermaLink="false">http://blog.falci.me/?p=288</guid>
		<description><![CDATA[Descrição: Site desenvolvido sobre a plataforma WordPress para empresa BDS Sistemas. O objetivo do site é exibir informações sobre a empresa e seus produtos. O site foi desenvolvido visando melhor a experiência dos visitante e facilitar a manutenção/edição do conteúdo. Tecnologias: PHP, MySQL, CSS, jQuery Link: www.sistemasbds.com.br]]></description>
			<content:encoded><![CDATA[<p>
<a href='http://blog.falci.me/portfolio/bds-sistemas/attachment/bds1/' title='Página Inicial'><img width="140" height="140" src="http://blog.falci.me/wp-content/uploads/2011/03/bds1-140x140.jpg" class="attachment-thumbnail" alt="Página Inicial" title="Página Inicial" /></a>
<a href='http://blog.falci.me/portfolio/bds-sistemas/attachment/bds2/' title='Formulário de Contato'><img width="140" height="140" src="http://blog.falci.me/wp-content/uploads/2011/03/bds2-140x140.jpg" class="attachment-thumbnail" alt="Formulário de Contato" title="Formulário de Contato" /></a>
<a href='http://blog.falci.me/portfolio/bds-sistemas/attachment/bds3/' title='Painel de Controle: Editar Página'><img width="140" height="140" src="http://blog.falci.me/wp-content/uploads/2011/03/bds3-140x140.jpg" class="attachment-thumbnail" alt="Painel de Controle: Editar Página" title="Painel de Controle: Editar Página" /></a>
<a href='http://blog.falci.me/portfolio/bds-sistemas/attachment/bds4/' title='Painel de Controle: Gerênciar Uploads'><img width="140" height="140" src="http://blog.falci.me/wp-content/uploads/2011/03/bds4-140x140.jpg" class="attachment-thumbnail" alt="Painel de Controle: Gerênciar Uploads" title="Painel de Controle: Gerênciar Uploads" /></a>
<span id="more-288"></span></p>
<p><strong>Descrição:</strong> Site desenvolvido sobre a plataforma WordPress para empresa BDS Sistemas. O objetivo do site é exibir informações sobre a empresa e seus produtos. O site foi desenvolvido visando melhor a experiência dos visitante e facilitar a manutenção/edição do conteúdo.</p>
<p><strong>Tecnologias:</strong> PHP, MySQL, CSS, jQuery</p>
<p><strong>Link:</strong> <a title="BDS Sistemas" href="http://www.sistemasbds.com.br" target="_blank" rel="nofollow">www.sistemasbds.com.br</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.falci.me/portfolio/bds-sistemas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Portal: Cade o Pessoal.com</title>
		<link>http://blog.falci.me/portfolio/portal-cade-o-pessoal-com/</link>
		<comments>http://blog.falci.me/portfolio/portal-cade-o-pessoal-com/#comments</comments>
		<pubDate>Fri, 25 Mar 2011 14:15:19 +0000</pubDate>
		<dc:creator>Falci</dc:creator>
				<category><![CDATA[Portfólio]]></category>

		<guid isPermaLink="false">http://blog.falci.me/?p=279</guid>
		<description><![CDATA[Descrição: Portal de entretenimento, notícias, horóscopo, classificados, agenda de eventos, videos, entre outros. Possui um painel de controle multi-usuário e com niveis de acesso. Tecnologias: Zend Framework (PHP), MySQL, jQuery e integação com redes sociais. Link: www.cadeopessoal.com]]></description>
			<content:encoded><![CDATA[
<a href='http://blog.falci.me/portfolio/portal-cade-o-pessoal-com/attachment/cop1/' title='Página Inicial'><img width="140" height="140" src="http://blog.falci.me/wp-content/uploads/2011/03/cop1-150x150.jpg" class="attachment-thumbnail" alt="Página Inicial" title="Página Inicial" /></a>
<a href='http://blog.falci.me/portfolio/portal-cade-o-pessoal-com/attachment/cop2/' title='Eventos'><img width="140" height="140" src="http://blog.falci.me/wp-content/uploads/2011/03/cop2-150x150.jpg" class="attachment-thumbnail" alt="Eventos" title="Eventos" /></a>
<a href='http://blog.falci.me/portfolio/portal-cade-o-pessoal-com/attachment/cop4/' title='Painel de Controle: Publicidade'><img width="140" height="140" src="http://blog.falci.me/wp-content/uploads/2011/03/cop4-150x150.jpg" class="attachment-thumbnail" alt="Painel de Controle: Publicidade" title="Painel de Controle: Publicidade" /></a>
<a href='http://blog.falci.me/portfolio/portal-cade-o-pessoal-com/attachment/cop5/' title='Painel de Controle: Notícias'><img width="140" height="140" src="http://blog.falci.me/wp-content/uploads/2011/03/cop5-150x150.jpg" class="attachment-thumbnail" alt="Painel de Controle: Notícias" title="Painel de Controle: Notícias" /></a>

<p><span id="more-279"></span><strong>Descrição:</strong> Portal de entretenimento, notícias, horóscopo, classificados, agenda de eventos, videos, entre outros. Possui um painel de controle multi-usuário e com niveis de acesso.</p>
<p><strong>Tecnologias:</strong> Zend Framework (PHP), MySQL, jQuery e integação com redes sociais.</p>
<p><strong>Link:</strong> <a title="Cade o Pessoal.com" href="http://www.cadeopessoal.com" target="_blank">www.cadeopessoal.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.falci.me/portfolio/portal-cade-o-pessoal-com/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CMS: mais7.com</title>
		<link>http://blog.falci.me/portfolio/cms-mais7-com/</link>
		<comments>http://blog.falci.me/portfolio/cms-mais7-com/#comments</comments>
		<pubDate>Fri, 25 Mar 2011 12:58:08 +0000</pubDate>
		<dc:creator>Falci</dc:creator>
				<category><![CDATA[Portfólio]]></category>

		<guid isPermaLink="false">http://blog.falci.me/?p=270</guid>
		<description><![CDATA[Descrição: Sistema desenvolvido para o portal Mais7.com. O sistema conta com um painel de controle simples e objetivo, onde cada empresa pode gerenciar seu site, criando e editando páginas, galerias de imagens, menus e outros itens. *O sistema possui mais de 300 empresas/clientes. Tecnologias: PHP, POO, MySQL, Ajax, jQuery, Tableless Participação: Daniel Avrella (Design) Links: [...]]]></description>
			<content:encoded><![CDATA[
<a href='http://blog.falci.me/portfolio/cms-mais7-com/attachment/cmsmais71/' title='inovkids.mais7.com'><img width="140" height="140" src="http://blog.falci.me/wp-content/uploads/2011/03/cmsmais71-150x150.jpg" class="attachment-thumbnail" alt="inovkids.mais7.com" title="inovkids.mais7.com" /></a>
<a href='http://blog.falci.me/portfolio/cms-mais7-com/attachment/cmsmais72/' title='canello.mais7.com'><img width="140" height="140" src="http://blog.falci.me/wp-content/uploads/2011/03/cmsmais72-150x150.jpg" class="attachment-thumbnail" alt="canello.mais7.com" title="canello.mais7.com" /></a>
<a href='http://blog.falci.me/portfolio/cms-mais7-com/attachment/cmsmais73/' title='reginamodas.mais7.com'><img width="140" height="140" src="http://blog.falci.me/wp-content/uploads/2011/03/cmsmais73-150x150.jpg" class="attachment-thumbnail" alt="reginamodas.mais7.com" title="reginamodas.mais7.com" /></a>
<a href='http://blog.falci.me/portfolio/cms-mais7-com/attachment/cmsmais74/' title='Formulário de contato'><img width="140" height="133" src="http://blog.falci.me/wp-content/uploads/2011/03/cmsmais74-150x143.jpg" class="attachment-thumbnail" alt="Formulário de contato" title="Formulário de contato" /></a>

<p><span id="more-270"></span><strong>Descrição: </strong>Sistema desenvolvido para o portal <a rel="nofollow" href="http://mais7.com/" target="_blank">Mais7.com</a>. O sistema conta com um painel de controle simples e objetivo, onde cada empresa pode gerenciar seu site, criando e editando páginas, galerias de imagens, menus e outros itens.<br />
*O sistema possui mais de 300 empresas/clientes.</p>
<p><strong>Tecnologias:</strong> PHP, POO, MySQL, Ajax, jQuery, Tableless</p>
<p><strong>Participação:</strong> Daniel Avrella (Design)</p>
<p><strong>Links:</strong> <a href="http://inovkids.mais7.com" rel="nofollow">inovkids.mais7.com</a>, <a href="http://canello.mais7.com" rel="nofollow">canello.mais7.com</a>, <a href="http://reginamodas.mais7.com" rel="nofollow">reginamodas.mais7.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.falci.me/portfolio/cms-mais7-com/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sistema: Compras WEB</title>
		<link>http://blog.falci.me/portfolio/sistema-compras-web/</link>
		<comments>http://blog.falci.me/portfolio/sistema-compras-web/#comments</comments>
		<pubDate>Fri, 25 Mar 2011 12:48:27 +0000</pubDate>
		<dc:creator>Falci</dc:creator>
				<category><![CDATA[Portfólio]]></category>

		<guid isPermaLink="false">http://blog.falci.me/?p=264</guid>
		<description><![CDATA[Descrição: Sistema desenvolvido para facilitar e simplificar a forma com que os funcionários solicitam materiais de expediente ao departamento de compras. Desenvolvido e em uso atualmente pela UNIPAR. O sistema foi apresentado com TCC no Curso Sup. de Análise e Desenvolvimento Sistemas (UNIPAR) Tecnologias: PHP, MySQL, jQuery, PDF]]></description>
			<content:encoded><![CDATA[
<a href='http://blog.falci.me/portfolio/sistema-compras-web/attachment/comprasweb1/' title='Página de Pedidos'><img width="140" height="140" src="http://blog.falci.me/wp-content/uploads/2011/03/comprasweb1-150x150.jpg" class="attachment-thumbnail" alt="Página de Pedidos" title="Página de Pedidos" /></a>
<a href='http://blog.falci.me/portfolio/sistema-compras-web/attachment/comprasweb2/' title='Lista dos Produtos'><img width="140" height="140" src="http://blog.falci.me/wp-content/uploads/2011/03/comprasweb2-150x150.jpg" class="attachment-thumbnail" alt="Lista dos Produtos" title="Lista dos Produtos" /></a>
<a href='http://blog.falci.me/portfolio/sistema-compras-web/attachment/comprasweb3/' title='Relatório de Produtos Solicitados'><img width="140" height="140" src="http://blog.falci.me/wp-content/uploads/2011/03/comprasweb3-150x150.jpg" class="attachment-thumbnail" alt="Relatório de Produtos Solicitados" title="Relatório de Produtos Solicitados" /></a>

<p><span id="more-264"></span><strong>Descrição:</strong> Sistema desenvolvido para facilitar e simplificar a forma com que os funcionários solicitam materiais de expediente ao departamento de compras. Desenvolvido e em uso atualmente pela <a href="http://unipar.br" target="_blank"><abbr title="Universidade Paranense">UNIPAR</abbr></a>. O sistema foi apresentado com <abbr title="Trabalho de Conclusão de Curso">TCC</abbr> no Curso Sup. de Análise e Desenvolvimento Sistemas (<a href="http://unipar.br" target="_blank"><abbr title="Universidade Paranense">UNIPAR</abbr></a>)</p>
<p><strong>Tecnologias:</strong> PHP, MySQL, jQuery, PDF</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.falci.me/portfolio/sistema-compras-web/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sistema: Agenda</title>
		<link>http://blog.falci.me/portfolio/sistema-agenda/</link>
		<comments>http://blog.falci.me/portfolio/sistema-agenda/#comments</comments>
		<pubDate>Fri, 25 Mar 2011 12:38:33 +0000</pubDate>
		<dc:creator>Falci</dc:creator>
				<category><![CDATA[Portfólio]]></category>

		<guid isPermaLink="false">http://blog.falci.me/?p=260</guid>
		<description><![CDATA[Descrição: Agenda de reservas de ambiêntes e equipamentos. Desenvolvido para uso interno na UNIPAR. Tecnologias: PHP, MySQL]]></description>
			<content:encoded><![CDATA[
<a href='http://blog.falci.me/portfolio/sistema-agenda/attachment/agenda1/' title='Tela principal'><img width="140" height="140" src="http://blog.falci.me/wp-content/uploads/2011/03/agenda1-150x150.jpg" class="attachment-thumbnail" alt="Tela principal" title="Tela principal" /></a>
<a href='http://blog.falci.me/portfolio/sistema-agenda/attachment/agenda2/' title='Adicionar nova reserva'><img width="140" height="140" src="http://blog.falci.me/wp-content/uploads/2011/03/agenda2-150x150.jpg" class="attachment-thumbnail" alt="Adicionar nova reserva" title="Adicionar nova reserva" /></a>

<p><span id="more-260"></span></p>
<p><strong>Descrição:</strong> Agenda de reservas de ambiêntes e equipamentos. Desenvolvido para uso interno na <a href="http://unipar.br" target="_blank"><abbr title="Universidade Paranaense">UNIPAR</abbr></a>.</p>
<p><strong>Tecnologias:</strong> PHP, MySQL</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.falci.me/portfolio/sistema-agenda/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

