Ver Mensaje Individual
  #4 (permalink)  
Antiguo 24/01/2002, 17:50
Avatar de mikel_gomez
mikel_gomez
 
Fecha de Ingreso: febrero-2001
Mensajes: 482
Antigüedad: 23 años, 2 meses
Puntos: 3
Re: ¿Cómo contar texto de un textarea?

Sir Matrix :

Fácil no ha sido, pero creo que está conseguido:

<pre>&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Expresiones regulares&lt;/title&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
function contar(texto) {
subtxt = texto.split('{') ;
er = /^[^}]*}[^}]*$/ ;
for(j=1; j&lt;subtxt.length; j++)
if (!er.test(subtxt[j])) {
alert('Llaves mal balanceadas');
return 0 ;
}
alert(subtxt.length-1);
return subtxt.length-1;
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form id=&quot;frm&quot;&gt;
&lt;textarea id=&quot;texto&quot; style=&quot;width: 640px; height: 400px;&quot;&gt;
habia una vez{|^|} ijsijadlk aksj {&lt; &gt;}ksadj {--O} jshjd {/0/} sjhdjhj
&lt;/textarea&gt;
&lt;br /&gt;
&lt;input type=&quot;button&quot; value=&quot;Contar ocurrencias entre llaves&quot;
onclick=&quot;contar(this.form.texto.value)&quot; /&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt; </pre>

Espero tus comentarios.
Saludos.

<style>.t{font: 8pt verdana; text-decoration: none; color: black;}</style><hr><span class="t"><a href="mailto:[email protected]" class="t" style="font: 10pt;">Mikel Gómez</a><br>Hay que aprender mucho para saber poco.</span>