Resultados 1 al 3 de 3
  1. #1
    Senior Member Google es mi amigo
    Fecha de ingreso
    20 jul, 07
    Mensajes
    601
    Poder de reputación
    464

    Unhappy Busco una función en Javascript

    A ver si alguien me puede ayudar.

    Necesito hacer una funcioncita en javascript que valide el texto introducido en un caja de texto.

    Pero esta caja de texto es una richtextbox que permite formato HTML.

    Lo que yo quiero es que me valide si el usuario ingresa otros tags html que no sean <b> <ul> y <li>

    O sea si me ponen <H1>hola</H1> lance un error, si me pone <i>...</i>, <table>, etc... tambien.

    Que solo me permita ingresar en el richtextboxx <b>..</b>, <ul>..</ul>, y <li>..</li>..


    Alguien sabe de alguna funcion ya hecha y comprobada que me permita hacer esto, quizás en jquery o el framework dojo, ya que son los dos que estoy utilizando.

    gracias.

  2. #2
    rel = 'nofollow' Soy accionista de Google!
    Fecha de ingreso
    29 oct, 04
    Ubicación
    MVD
    Edad
    32
    Mensajes
    1,309
    Poder de reputación
    800

    Predeterminado

    Hola:

    Que sea un textarea enriquecido no quita que siga siendo un textarea, así que usando expresiones regulares podés validarlo, yo la verdad no manejo js pero si buscas un rato en google algo como "validate html textarea" capáz das con algo ya hecho, si en cambio manejas bien js lo podés hacer vos.

    Saludos!

  3. #3
    Senior Member Google es mi amigo
    Fecha de ingreso
    20 jul, 07
    Mensajes
    601
    Poder de reputación
    464

    Predeterminado

    Bueno si alguien la necesita para algo aca esta:


    Código:
    function strip_tags_html (str, allowed_tags) {
    
    	var key = '', allowed = false;
    	var matches = [];
    	var allowed_array = [];
    	var allowed_tag = '';
    	var i = 0;
    	var k = '';
    	var html = '';
    	var replacer = function (search, replace, str) {
    		return str.split(search).join(replace);
    	};
    
    	// Build allowes tags associative array
    	if (allowed_tags) {
    		allowed_array = allowed_tags.match(/([a-zA-Z0-9]+)/gi);
    	}
    
    	str += '';
    
    	// Match tags
    	matches = str.match(/(<\/?[\S][^>]*>)/gi);
    
    	// Go through all HTML tags
    	for (key in matches) {
    		if (isNaN(key)) {
    			// IE7 Hack
    			continue;
    		}
    
    		// Save HTML tag
    		html = matches[key].toString();
    
    		// Is tag not in allowed list? Remove from str!
    		allowed = false;
    
    		// Go through all allowed tags
    		for (k in allowed_array) {
    			// Init
    			allowed_tag = allowed_array[k];
    			i = -1;
    
    			if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+'>');}
    			if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+' ');}
    			if (i != 0) { i = html.toLowerCase().indexOf('</'+allowed_tag)   ;}
    
    			// Determine
    			if (i == 0) {
    				allowed = true;
    				break;
    			}
    		}
    
    		if (!allowed) {
    			str = replacer(html, "", str); // Custom replace. No regexing
    		}
    	}
    
    	return str;
    }

 

 

Temas similares

  1. Respuestas: 0
    Último mensaje: 28/02/2011, 12:56

Permisos de publicación

  • No puedes crear nuevos temas
  • No puedes responder temas
  • No puedes subir archivos adjuntos
  • No puedes editar tus mensajes
  •  

Search Engine Friendly URLs by vBSEO ©2011, Crawlability, Inc.