Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/03/2012, 10:09
yonerflash
 
Fecha de Ingreso: noviembre-2004
Ubicación: Medellín
Mensajes: 121
Antigüedad: 19 años, 6 meses
Puntos: 1
Pregunta Validación textbox

Hola, estoy practicando lo que leí he hice esta validación de un textBox, pero no me funciona. Me pueden decir que hice mal? Gracias

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
<script language="javascript" type="text/javascript">
function validaCampo(campo) {
var caracter
var caracteres = "abcdefghijklmnopqrstuvwxyzñABCDEFGHIJKLMNOPQRSTUV WXYZÑáéíóúÁÉÍÓÚ" + String.fromCharCode(13)
var contador = 0

for (var i=0; i < campo.length; i++) {
caracter = campo.substring(i, i + 1)
if (caracteres.indexOf(caracter) != -1) {
contador++
} else {
alert("ERROR: No se acepta el caracter '" + ubicacion + "'.")
}
}
alert("Datos correctos.")
}
</script>
</head>

<body>
<form id="nuevo" name="nuevo" method="post">
<label>
<input type="text" name="nombre" id="nombre" /><br /><br />
</label>
<label>
<input type="button" name="but" id="but" value="Enviar" OnClick="validaCampo(this.nombre.value);"/>
</label>
</form>
</body>
</html>