Foros del Web » Programando para Internet » Javascript »

Validacion Formulario

Estas en el tema de Validacion Formulario en el foro de Javascript en Foros del Web. Hola: La validacion funciona bien, pero tengo q incluir la validacion numerica y aqui esta el formulario y si pueden incluir la validacion el select ...
  #1 (permalink)  
Antiguo 02/11/2004, 13:52
Avatar de alexis77  
Fecha de Ingreso: diciembre-2003
Mensajes: 119
Antigüedad: 20 años, 4 meses
Puntos: 0
Validacion Formulario

Hola:

La validacion funciona bien, pero tengo q incluir la validacion numerica y aqui esta el formulario
y si pueden incluir la validacion el select no estaria mal...
acontinuacion el forulario q tengo


registro.htm

<script>
function Validar(form){
if(form.nombre.value == ""){
alert("ERROR: Ingrese su(s) Nombre(s). "); form.nombre.focus(); return;
}
if(form.apellidos.value == ""){
alert("ERROR: Ingrese sus Apellidos. "); form.apellidos.focus(); return;
}
if (form.email.value.indexOf('@', 0) == -1 || form.email.value.indexOf('.', 0) == -1){
alert("ERROR: Ingrese y/o dirección de E-mail inválida. "); form.email.focus(); return;
}
if(form.telefono.value == ""){
alert("ERROR: Ingrese su teléfono solo numeros. "); form.telefono.focus(); return;
}
if(form.ci.value == ""){
alert("ERROR: Ingrese su CI solo numeros. "); form.ci.focus(); return;
}

form.submit();
}


</script>

<table width="100%" border="0" cellpadding="0" cellspacing="3">
<form name="myForm" action="" method="post">
<tr>
<td class="TextForm" align="right"><b>Nombres:</b></td>
<td><input type="text" name="nombre" size="30"></td>
</tr>
<tr>
<td class="TextForm" align="right"><b>Apellidos:</b></td>
<td><input type="text" name="apellidos" size="30"></td>
</tr>
<tr>
<td class="TextForm" align="right"><b>Estado:</b></td>
<td>
<select name="estado">
<option value="0">Seleccione
<option value="1">Distrito capital
<option value="2">Miranda
<option value="3">Zulia
</select>
</td>
</tr>
<tr>
<td class="TextForm" align="right"><b>Ciudad:</b></td>
<td>
<select name="ciudad">
<option value="0">Seleccione
<option value="1">Caracas
<option value="2">Turin
</select>
</td>
</tr>
<tr>
<td class="TextForm" align="right"><b>Correo Electrónico:</b></td>
<td><input type="text" name="email" size="15"></td>
</tr>
<tr>
<td class="TextForm" align="right"><b>Teléfono:</b></td>
<td><input type="text" name="telefono" size="15"></td>
</tr>
<tr>
<td class="TextForm" align="right"><b>CI:</b></td>
<td><input type="text" name="ci" size="10"> </td>
</tr>
<tr>
<td valign="top" class="TextForm" align="right"><b>Comentarios:</b></td>
<td><textarea name="comentario" cols="30" rows="5"></textarea></td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="hidden" name="accion" value="enviar">
<input type="button" value=" Enviar " name="enviar" onClick="Validar(this.form)">
<input type="reset" value=" Borrar ">
</td>
</tr>
</form>
</table>
  #2 (permalink)  
Antiguo 02/11/2004, 14:26
 
Fecha de Ingreso: octubre-2004
Ubicación: España
Mensajes: 894
Antigüedad: 19 años, 6 meses
Puntos: 3
Hola, Alexis
¿Lo que quieres es verificar que entren sólo números?
Mira a ver si esto resuelve tu problema:
http://www.forosdelweb.com/f13/ayuda-sobre-text-box-241134/
  #3 (permalink)  
Antiguo 02/11/2004, 14:57
 
Fecha de Ingreso: octubre-2004
Ubicación: España
Mensajes: 894
Antigüedad: 19 años, 6 meses
Puntos: 3
Para validar el select:
http://www.forosdelweb.com/f13/validaciones-usando-javascript-240508/
  #4 (permalink)  
Antiguo 02/11/2004, 17:39
Avatar de alexis77  
Fecha de Ingreso: diciembre-2003
Mensajes: 119
Antigüedad: 20 años, 4 meses
Puntos: 0
al formulario q tiene las validaciones quiero agregar o incluir la validacion numerica en el campo CI y TELEFONO
  #5 (permalink)  
Antiguo 03/11/2004, 13:40
Avatar de SiR.CARAJ0DIDA  
Fecha de Ingreso: junio-2004
Ubicación: Acá
Mensajes: 1.166
Antigüedad: 19 años, 9 meses
Puntos: 4
hice una asi nomas, a ver si te anda;
cont = 0;
valor = form.ci.value;
for (i=0;i<valor.length;i++)
{
if (valor.charAt(i) >= 0 && valor.charAt(i) <= 9) cont++;
}
if (cont != valor.length) alert('Solo se admiten numerosss!!!!!');
  #6 (permalink)  
Antiguo 03/11/2004, 14:43
 
Fecha de Ingreso: octubre-2004
Ubicación: España
Mensajes: 894
Antigüedad: 19 años, 6 meses
Puntos: 3
Se me adelantó SiR, pero ahí va mi solución:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
function Validar(form){
if(form.nombre.value == ""){
alert("ERROR: Ingrese su(s) Nombre(s). "); form.nombre.focus(); return;
}
if(form.apellidos.value == ""){
alert("ERROR: Ingrese sus Apellidos. "); form.apellidos.focus(); return;
}

if(form.estado.selectedIndex==0){
alert("ERROR: Ingrese el Estado. "); form.estado.focus(); return;
}
if(form.ciudad.selectedIndex==0){
alert("ERROR: Ingrese la Ciudad. "); form.ciudad.focus(); return;
}

if (form.email.value.indexOf('@', 0) == -1 || form.email.value.indexOf('.', 0) == -1){
alert("ERROR: Ingrese y/o dirección de E-mail inválida. "); form.email.focus(); return;
}
if(!validaNumeros(form.telefono.value)){
alert("ERROR: Ingrese su teléfono solo numeros. "); form.telefono.focus(); return;
}
if(!validaNumeros(form.ci.value)){
alert("ERROR: Ingrese su CI solo numeros. "); form.ci.focus(); return;
}

form.submit();
}

function validaNumeros(tx) {
for (i=0;i<tx.length;i++) {
var codi = tx.charCodeAt(i)
if ( codi<48 || codi>57 ) {
return false
}
}
if (tx!='') return true
else return false
}

</script>
</head>
<body>

<table width="100%" border="0" cellpadding="0" cellspacing="3">
<form name="myForm" action="" method="post">
<tr>
<td class="TextForm" align="right"><b>Nombres:</b></td>
<td><input type="text" name="nombre" size="30"></td>
</tr>
<tr>
<td class="TextForm" align="right"><b>Apellidos:</b></td>
<td><input type="text" name="apellidos" size="30"></td>
</tr>
<tr>
<td class="TextForm" align="right"><b>Estado:</b></td>
<td>
<select name="estado">
<option value="0">Seleccione
<option value="1">Distrito capital
<option value="2">Miranda
<option value="3">Zulia
</select>
</td>
</tr>
<tr>
<td class="TextForm" align="right"><b>Ciudad:</b></td>
<td>
<select name="ciudad">
<option value="0">Seleccione
<option value="1">Caracas
<option value="2">Turin
</select>
</td>
</tr>
<tr>
<td class="TextForm" align="right"><b>Correo Electrónico:</b></td>
<td><input type="text" name="email" size="15"></td>
</tr>
<tr>
<td class="TextForm" align="right"><b>Teléfono:</b></td>
<td><input type="text" name="telefono" size="15"></td>
</tr>
<tr>
<td class="TextForm" align="right"><b>CI:</b></td>
<td><input type="text" name="ci" size="10"> </td>
</tr>
<tr>
<td valign="top" class="TextForm" align="right"><b>Comentarios:</b></td>
<td><textarea name="comentario" cols="30" rows="5"></textarea></td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="hidden" name="accion" value="enviar">
<input type="button" value=" Enviar " name="enviar" onClick="Validar(this.form)">
<input type="reset" value=" Borrar ">
</td>
</tr>
</form>
</table>

</body>
</html>
  #7 (permalink)  
Antiguo 04/11/2004, 14:40
Avatar de alexis77  
Fecha de Ingreso: diciembre-2003
Mensajes: 119
Antigüedad: 20 años, 4 meses
Puntos: 0
Funciona perfectamente pero tengo otro lio, y disculpen la molestia

quiero q en el campo telefono puedan ingresar d la siguiente forma 000-00-00

y gracias a todos
  #8 (permalink)  
Antiguo 06/11/2004, 11:46
 
Fecha de Ingreso: octubre-2004
Ubicación: España
Mensajes: 894
Antigüedad: 19 años, 6 meses
Puntos: 3
Lo más sencillo será simplemente ignorar los guiones en la validación.
Cambia esto:
Código:
if(!validaTfno(form.telefono.value)){
alert("ERROR: Ingrese su teléfono solo numeros. "); form.telefono.focus(); return;
}
y añade esto:
Código:
function validaTfno(tx) {
	var tx1 = ''
	for (i=0;i<tx.length;i++) {
		if ( tx.charAt(i) != '-' ) { tx1 += tx.charAt(i) }
	}
	return validaNumeros(tx1)
}
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 14:30.