error al validar string con ñ o '
Publicado por aliciavs (1 intervención) el 02/12/2009 11:36:54
Desde la jsp antes de enviar los datos valido los datos del formulario, con
function valida(paso)
{
if(!ValidString("Nombre cliente",document.clienteForm.nome)){
document.form.nome.focus();
return false;
}else if ...
}else{
//submit
}
}
La función Validstrig está en un js
var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnñopqrstuvwxyz";
var uppercaseLetters = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZ";
var simbolos = ".,:;-_�?�!\\+-/=()%[]*<>@,´";
var space= " ";
var alfaNumerico = digits + lowercaseLetters + uppercaseLetters + space + simbolos;
function ValidString(nombre,campo){
if (campo.value != ""){
if(!BusqCaracteres(campo.value)){
alert("el campo " + nombre + " contiene caracteres extraños");
campo.focus();
return (false);
}
}
return true;
}
function BusqCaracteres(texto){
var txt = texto.toString();
var valido = true;
for(var i = 0;i < texto.length;i++)
{
var oneChar = txt.charAt(i);
if (alfaNumerico.indexOf(oneChar) == '-1')
{
valido = false;
}
}
return valido;
}
Esta es la cabecera de la jsp
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META http-equiv="Content-Style-Type" content="text/css">
Pero al validar da error al encontrar ´o ñ, que estoy haciendo mal? Pueden ayudarme?
function valida(paso)
{
if(!ValidString("Nombre cliente",document.clienteForm.nome)){
document.form.nome.focus();
return false;
}else if ...
}else{
//submit
}
}
La función Validstrig está en un js
var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnñopqrstuvwxyz";
var uppercaseLetters = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZ";
var simbolos = ".,:;-_�?�!\\+-/=()%[]*<>@,´";
var space= " ";
var alfaNumerico = digits + lowercaseLetters + uppercaseLetters + space + simbolos;
function ValidString(nombre,campo){
if (campo.value != ""){
if(!BusqCaracteres(campo.value)){
alert("el campo " + nombre + " contiene caracteres extraños");
campo.focus();
return (false);
}
}
return true;
}
function BusqCaracteres(texto){
var txt = texto.toString();
var valido = true;
for(var i = 0;i < texto.length;i++)
{
var oneChar = txt.charAt(i);
if (alfaNumerico.indexOf(oneChar) == '-1')
{
valido = false;
}
}
return valido;
}
Esta es la cabecera de la jsp
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META http-equiv="Content-Style-Type" content="text/css">
Pero al validar da error al encontrar ´o ñ, que estoy haciendo mal? Pueden ayudarme?
Valora esta pregunta


0