Category Archives: JavaScript

Retorna Data e Hora Atual JavaScript

Função rápida para retornar data e hora via JavaScript. [js] function RetornaDataHoraAtual(){ var dNow = new Date(); var localdate = dNow.getDate() + ‘/’ + (dNow.getMonth()+1) + ‘/’ + dNow.getFullYear() + ‘ ‘ + dNow.getHours() + ‘:’ + dNow.getMinutes(); return localdate; } [/js] Até a próxima!

<span class="entry-utility-prep entry-utility-prep-cat-links">Posted in</span> JavaScript | <span class="entry-utility-prep entry-utility-prep-tag-links">Tagged</span> | Leave a comment

Função de Validação de Data JavaScript

Validação de data através do JavaScript. Retorna false caso a data esteja inválida. [js] function ValidarData(data){ if(data.length < 10) return false; // verificando data var dia = data.substr(0,2); var barra1 = data.substr(2,1); var mes = data.substr(3,2); var barra2 = data.substr(5,1); var ano = data.substr(6,4); if(barra1!="/"||barra2!="/"||isNaN(dia)||isNaN(mes)||isNaN(ano)||dia>31||mes>12) return false; if((mes==4||mes==6||mes==9||mes==11) && dia==31) return false; if(mes==2 && (dia>29||(dia==29 […]

<span class="entry-utility-prep entry-utility-prep-cat-links">Posted in</span> JavaScript | <span class="entry-utility-prep entry-utility-prep-tag-links">Tagged</span> | Leave a comment

Retorna Parâmetro URL por JavaScript

Obter parâmetro da URL através do JavaScript. [js] /function ObtemParametro(name){ var results = new RegExp(‘[\?&]’ + name + ‘=([^&#]*)’).exec(window.location.href); return results[1] || 0; } [/js] Até a próxima!!

<span class="entry-utility-prep entry-utility-prep-cat-links">Posted in</span> JavaScript | <span class="entry-utility-prep entry-utility-prep-tag-links">Tagged</span> | Leave a comment

Verificar se valor existe na String Javascript

Algumas formas de verificar se valor existe em uma string utilizando JavaScript. 1. (ES6) includes [js] var string = “foo”, substring = “oo”; string.includes(substring); [/js] 2. search [js] var string = “foo”, expr = “/oo/”; string.search(expr); [/js] 3. lodash includes [js] var string = “foo”, substring = “oo”; _.includes(string, substring); [/js] 4. RegExp [js] var […]

<span class="entry-utility-prep entry-utility-prep-cat-links">Posted in</span> JavaScript | <span class="entry-utility-prep entry-utility-prep-tag-links">Tagged</span> , | Leave a comment

Como o Facebook pode Alavancar suas Vendas

01 – Conhecer seu público Com uma fanpage, você tem conhecimento dos perfis do público que curte seu negócio, as suas preferências, idade, profissão, sexo e outros, além de nome, e-mail e a sua localidade. Com as informações você consegue fazer campanhas direcionadas para seu público-alvo e potencializar as suas vendas. 02 – Segmentação É […]

<span class="entry-utility-prep entry-utility-prep-cat-links">Posted in</span> .NET, AngularJS, JavaScript, JQuery, Linux, MySQL, PHP, Prestashop, SharePoint, SQL | <span class="entry-utility-prep entry-utility-prep-tag-links">Tagged</span> , , | Leave a comment

Remover DIV pelo texto ou title

Simples forma de remover uma div pelo text ou title. [js] $(“[title=’Criar novo site de projeto’]”).remove(); $(“[text=’Criar novo site de projeto’]”).remove(); [/js]

<span class="entry-utility-prep entry-utility-prep-cat-links">Posted in</span> JavaScript, JQuery | <span class="entry-utility-prep entry-utility-prep-tag-links">Tagged</span> , | Leave a comment

Verificar se usuário faz parte de grupo SharePoint

A função abaixo retorna se o usuário SharePoint faz parte de um determinado grupo. Se o retorno for verdadeiro o usuário faz parte do grupo. [js] function isMember(groupName) { var obj = null; var url = _spPageContextInfo.webAbsoluteUrl + “/_api/web/sitegroups/getByName(‘”+groupName+”‘)/Users?$filter=Id eq ” + _spPageContextInfo.userId; var requestHeaders = { “accept” : “application/json;odata=verbose” }; $.ajax({ url : url, […]

<span class="entry-utility-prep entry-utility-prep-cat-links">Posted in</span> JavaScript, SharePoint | <span class="entry-utility-prep entry-utility-prep-tag-links">Tagged</span> , , | Leave a comment

Função JavaScript para validação de CPF

Função para validação de CPF. [js] /*Função que valida Cpf*/ function validarCPF( campo ){ var cpf = campo.value; cpf = remove(cpf, “.”); cpf = remove(cpf, “-“); if(cpf.length != 11 || cpf == “00000000000” || cpf == “11111111111” || cpf == “22222222222” || cpf == “33333333333” || cpf == “44444444444” || cpf == “55555555555” || cpf […]

<span class="entry-utility-prep entry-utility-prep-cat-links">Posted in</span> JavaScript | <span class="entry-utility-prep entry-utility-prep-tag-links">Tagged</span> | Leave a comment

Sleep “Thread” em JavaScript

O exemplo que mostro a seguir mostra como fazer uma “thread sleep” via JavaScript. [js] function sleepFor( sleepDuration ){ var now = new Date().getTime(); while(new Date().getTime() < now + sleepDuration){ /* do nothing */ } } [/js] Exemplo de uso [js] function demo(){ sleepFor(2000); console.log("Olá! Eu sou um teste."); } demo(); [/js] Prático!

<span class="entry-utility-prep entry-utility-prep-cat-links">Posted in</span> AngularJS, JavaScript | <span class="entry-utility-prep entry-utility-prep-tag-links">Tagged</span> | Leave a comment