Skip to content

Instantly share code, notes, and snippets.

@javiertapia
javiertapia / jquery.validate.rut.js
Created February 16, 2009 14:03
Validar rut mediante jQuery.Validate
function validaRut(campo){
if ( campo.length == 0 ){ return false; }
if ( campo.length < 8 ){ return false; }
campo = campo.replace('-','')
campo = campo.replace(/\./g,'')
var suma = 0;
var caracteres = "1234567890kK";
var contador = 0;
@javiertapia
javiertapia / gist:3709436
Created September 12, 2012 19:51
Activar links dentro de un texto
/*
Busca las urls (http://..., www...) y direcciones de correo electrónico dentro de un texto
y los rodea con los tags <a> correspondientes.
*/
function activar_links($text){
$text = preg_replace("/(^|[\n ])([\w]*?)([\w]*?:\/\/[\w]+[^ \"\n\r\t<]*)/is",
"$1$2<a href=\"$3\" >$3</a>", $text);
$text = preg_replace("/(^|[\n ])([\w]*?)((www)\.[^ \"\t\n\r<]*)/is",
"$1$2<a href=\"http://$3\" >$3</a>", $text);
$text = preg_replace("/(^|[\n ])([\w]*?)((ftp)\.[^ \,\"\t\n\r<]*)/is",
@javiertapia
javiertapia / gist:3707164
Created September 12, 2012 14:53
(PHP5) Extract Zip file
$fn = explode('.', $_FILES['archivo']['name']);
$ext = array_pop($fn);
if($ext == 'zip'){
$files = array();
$zip = new ZipArchive();
if( $zip->open($_FILES['archivo']['tmp_name']) ){
for($i=0; $i<$zip->numFiles; $i++){
$file = $zip->statIndex($i);
$files[] = $file['name'];
}