Resultados 1 al 3 de 3
-
22/04/2011, 21:48 #1
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.
-
22/04/2011, 23:00 #2rel = 'nofollow' Soy accionista de Google!
- Fecha de ingreso
- 29 oct, 04
- Ubicación
- MVD
- Edad
- 32
- Mensajes
- 1,309
- Poder de reputación
- 800
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!Conversor de monedas (βeta) - [ Twitter ]
-
25/04/2011, 20:02 #3
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
-
Busco diseñador con conocimientos en HTML, CSS, PHP y JAVASCRIPT
Por gandalf en el foro Diseño WebRespuestas: 0Último mensaje: 28/02/2011, 12:56



LinkBack URL
About LinkBacks



Citar

