Ver Mensaje Individual
  #2 (permalink)  
Antiguo 12/03/2002, 12:48
bet
 
Fecha de Ingreso: febrero-2001
Mensajes: 292
Antigüedad: 24 años
Puntos: 0
Re: contador de palabras

Modifiqué tu código... fijate si algo así te sirve....

Código:
<html>
<head><title>Expresiones regulares</title>

<script type="text/javascript"> 
var letras = /^([a-z]|[A-Z]|á|é|í|ó|ú|ñ|ü|\.|-|\n)+$/ 
var car=" ";


function contar(){
	var output = "";
	input = frm.texto.value;

	for (var i = 0; i < input.length; i++) {
		if ((input.charCodeAt(i) == 13) && (input.charCodeAt(i + 1) == 10)) {
			i++;
			output += " ";
		} 
		else {
			output += input.charAt(i);
	   }
	}

	var count=0;
	subtxt = output.split(car); 

	for(j=0; j<subtxt.length; j++){
		if (letras.test(subtxt[j]))
			count++;
	} 
	frm.total.value = count; 
} 
</script> 
</head> 
<body> 
<form id="frm"> 
<textarea id="texto" style="width: 500px; height: 150px;"></textarea><br> 
<input type="button" value="Contar" onclick="contar()"> 
<input type="text" name="total" readonly> 

</form> 
</body>
</html>
<hr noshade size=1><img src="http://www.gograph.com/Images-8712/ClipArt/cat03.gif" height="50" border=0 align="absmiddle"> <font size="2" face="verdana" color="#000000">bet[/CODE]