<?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>Artigos sobre jQuery, XHTML, CSS e PHP &#124; Julio Bitencourt &#187; expressões regulares</title>
	<atom:link href="http://www.juliobitencourt.com/tag/expressoes-regulares/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.juliobitencourt.com</link>
	<description>Artigos e tutoriais sobre desenvolvimento web, jQuery, HTML, PHP, CSS e outras tecnologias.</description>
	<lastBuildDate>Sat, 17 Jul 2010 18:18:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Validar e-mail com jQuery</title>
		<link>http://www.juliobitencourt.com/2009/03/validar-e-mail-com-jquery/</link>
		<comments>http://www.juliobitencourt.com/2009/03/validar-e-mail-com-jquery/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 20:37:43 +0000</pubDate>
		<dc:creator>Julio Bitencourt</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[expressões regulares]]></category>

		<guid isPermaLink="false">http://www.juliobitencourt.com/?p=36</guid>
		<description><![CDATA[Você já precisou validar a inclusão de um endereço de email em seus formulários?
Com jQuery e Expressões Regulares é super simples. Vamos lá!
Quem ainda não sabe nada sobre jQuery pode conferir clicando aqui
Quem ainda não sabe nada sobre Expressões Regulares pode conferir clicando aqui e aqui


1
2
3
4
5
6
7
&#60;form id=&#34;formulario&#34; method=&#34;post&#34;&#62;
    &#60;fieldset&#62;
    [...]]]></description>
			<content:encoded><![CDATA[<p>Você já precisou validar a inclusão de um endereço de email em seus formulários?<br />
Com jQuery e Expressões Regulares é super simples. Vamos lá!</p>
<p>Quem ainda não sabe nada sobre jQuery pode conferir <a title="Introdução ao jQuery" href="http://contagia.com.br/blog/2008/11/21/introducao-ao-jquery/" target="_blank">clicando aqui</a><br />
Quem ainda não sabe nada sobre Expressões Regulares pode conferir clicando <a title="Expressões Regulares" href="http://pt.wikipedia.org/wiki/Express%C3%A3o_regular" target="_blank">aqui</a> e <a title="Guia de Expressões Regulares" href="http://guia-er.sourceforge.net/" target="_blank">aqui</a></p>
<p><span id="more-36"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;formulario&quot;</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;post&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fieldset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label</span> <span style="color: #000066;">for</span>=<span style="color: #ff0000;">&quot;email&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>E-mail<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;email&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;validaemail&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;email&quot;</span> <span style="color: #000066;">size</span>=<span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;enviar&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Enviar&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fieldset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/form<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Como podem ver, o código XHTML acima é simples e não requer explicação adicional. Quem tiver dúvidas pode perguntar nos comentários</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>ready<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#formulario&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>submit<span style="color: #009900;">&#40;</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#email&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>val<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			  <span style="color: #000000; font-weight: bold;">var</span> regmail <span style="color: #339933;">=</span> <span style="color: #339933;">/</span>^<span style="color: #009900;">&#91;</span>\w<span style="color: #339933;">!</span><span style="color: #666666; font-style: italic;">#$%&amp;amp;'*+\/=?^`{|}~-]+(\.[\w!#$%&amp;amp;'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;</span>
			  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>regmail<span style="color: #339933;">.</span>test<span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#email&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>val<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				   alert<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;E-mail válido&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
				   alert<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;E-mail inválido&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				   <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span>
			  <span style="color: #009900;">&#125;</span>
		 <span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>Explicação do script</strong></p>
<p>Linha 1 &#8211; Indicamos que o script só será executado após o carregamento do documento pelo browser.<br />
Linha 2 &#8211; Atribuímos uma função ao evento submit do formulário. Ou seja, antes do envio do formulário será executado o código de verificação do e-mail.<br />
Linha 3 &#8211; Verificamos se algo foi digitado no campo &#8220;#email&#8221;<br />
Linha 4 &#8211; Criamos uma variável com a ER utilizada para validar o e-email. Neste artigo não irei explicar o funcionamento desta ER.<br />
Linha 5 &#8211; Submetemos o valor digitado no campo &#8220;#email&#8221; à ER utilizando o <a href="http://www.w3schools.com/jsref/jsref_test_regexp.asp" target="_blank">método test do javascript</a></p>
<p>Esta função retorna <em>true </em>caso o valor digitado no campo &#8220;#email&#8221; seja válido ou <em>false </em>caso seja um e-mail inválido.</p>
<p>Se quiser ver o script em funcionamento <a title="Teste de validação de email com jQuery" href="http://www.juliobitencourt.com/exemplos/validar_e_mail_com_jquery.html" target="_blank">clique aqui</a><br />
<h3 class='related_post_title'>Já que chegou até aqui, que tal ler isto?</h3>
<ul class='related_post'>
<li>Este post não tem posts relacionados</li>
</ul>


<!-- Begin TwitThis script (http://twitthis.com/) -->
<div style="text-align:left;">
<script type="text/javascript" src="http://s3.chuug.com/chuug.twitthis.scripts/twitthis.js"></script>
<script type="text/javascript">
<!--
document.write('<a href="javascript:;" onclick="TwitThis.pop();"><img src="http://s3.chuug.com/chuug.twitthis.resources/twitthis_grey_72x22.gif" alt="TwitThis" style="border:none;" /></a>');
//-->
</script>
</div>
<!-- /End -->

<!-- boo-widget start -->
					<script type="text/javascript">
					bb_keywords = "expressões regulares";
					bb_bid  = "";
					bb_lang  = "";
					bb_name = "custom";bb_limit = "7";bb_format = "bbc";</script>
					<script type="text/javascript" src="http://widgets.boo-box.com/javascripts/embed.js"></script>
					<!-- boo-widget end -->]]></content:encoded>
			<wfw:commentRss>http://www.juliobitencourt.com/2009/03/validar-e-mail-com-jquery/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
