This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Paginação com Ordenação e Consulta</title> | |
<style> | |
.pagination { | |
margin-top: 20px; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Op } = require("sequelize"); | |
Post.findAll({ | |
where: { | |
[Op.and]: [{ a: 5 }, { b: 6 }], // (a = 5) AND (b = 6) | |
[Op.or]: [{ a: 5 }, { b: 6 }], // (a = 5) OR (b = 6) | |
someAttribute: { | |
// Basics | |
[Op.eq]: 3, // = 3 | |
[Op.ne]: 20, // != 20 | |
[Op.is]: null, // IS NULL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nomeDoCampo: { | |
type: STRING, | |
allowNull: true, | |
set(valor) { | |
if (typeof valor === 'object') { | |
this.setDataValue('nomeDoCampo', valor.join(' e ')) | |
} else { | |
this.setDataValue('nomeDoCampo', valor) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function contaParamentros(){ | |
$numArgs = func_num_args(); | |
if($numArgs > 3){ | |
echo "<strong style='color: orange;'>Ops, você passou ".$numArgs." parâmetros. O número máximo permitido são 3 parâmetros.</strong>"; | |
}elseif($numArgs < 1){ | |
echo "<strong style='color: red;'>Ops, esta função precisa de, pelo menos, um argumento.</strong>"; | |
}else{ | |
echo "<div style='color: green; font-weight: bold;'>"; | |
echo "Muito bem, agora a função está perfeita!"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$valor = '(99) 99999-9999'; | |
if (preg_match('/^\([0-9]{2}\)?\s?[0-9]{4,5}-[0-9]{4}$/', $valor)): | |
echo 'Fone válido'; | |
else: | |
echo 'Fone inválido'; | |
endif; | |
// Saída Fone válido |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$valor = '18135-690'; | |
if (preg_match('/[0-9]{5,5}([-]?[0-9]{3})?$/', $valor)): | |
echo 'CEP válido'; | |
else: | |
echo 'CEP inválido'; | |
endif; | |
// Saída CEP válido |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$extensoes_aceitas = array('bmp' ,'png', 'svg', 'jpeg', 'jpg'); | |
$array_extensoes = explode('.', $_FILES['foto']['name']); | |
$extensao = strtolower(end($array_extensoes)); | |
if (array_search($extensao, $extensoes_aceitas) === false): | |
echo 'Extensão válida'; | |
else: | |
echo 'Extensão inválida'; | |
endif; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$valor = '25/12/2016'; | |
$arraData = explode('/', $valor); | |
if(checkdate($arraData[1], $arraData[0], $arraData[2])): | |
echo 'Data válida.'; | |
else: | |
echo 'Data inválida.'; | |
endif; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function isCNPJValido($valor){ | |
$cnpj = str_pad(str_replace(array('.','-','/'),'',$valor),14,'0',STR_PAD_LEFT); | |
if (strlen($cnpj) != 14): | |
return false; | |
else: | |
for($t = 12; $t < 14; $t++): | |
for($d = 0, $p = $t - 7, $c = 0; $c < $t; $c++): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function isCPFValido($valor){ | |
$valor = str_replace(array('.','-','/'), "", $valor); | |
$cpf = str_pad(preg_replace('[^0-9]', '', $valor), 11, '0', STR_PAD_LEFT); | |
if (strlen($cpf) != 11 || $cpf == '00000000000' || $cpf == '11111111111' || $cpf == '22222222222' || $cpf == '33333333333' || $cpf == '44444444444' || $cpf == '55555555555' || $cpf == '66666666666' || $cpf == '77777777777' || $cpf == '88888888888' || $cpf == '99999999999'): | |
return false; | |
else: | |
for ($t = 9; $t < 11; $t++): |
NewerOlder