El sitio más completo sobre programación, recursos web y herramientas online para Webmasters
Fecha: 20/01/2003

validar numeros integrales con javascript

sencilla funcion javascript que se encarga de validar numeros integrales

Código Javascript


<script type="text/javascript">
function IsInt( numstr, allowNegatives ) {
// Return immediately if an invalid value was passed in
if (numstr+"" == "undefined" || numstr+"" == "null" || numstr+"" == "")
return false;
// Default allowNegatives to true when undefined or null
if (allowNegatives+"" == "undefined" || allowNegatives+"" == "null")
allowNegatives = true;
var isValid = true;
// convert to a string for performing string comparisons.
numstr += "";
// Loop through string and test each character. If any
// character is not a number, return a false result.
// Include special case for negative numbers (first char == '-').
for (i = 0; i < numstr.length; i++) {
if (!((numstr.charAt(i) >= "0") && (numstr.charAt(i) <= "9") || (numstr.charAt(i) == "-"))) {
isValid = false;
break;
} else if ((numstr.charAt(i) == "-" && i != 0) ||
(numstr.charAt(i) == "-" && !allowNegatives)) {
isValid = false;
break;
}

} // END for

return isValid;
} // end IsInt

validar numeros integrales con javascript Categoría: Javascript, Funciones

Compartir validar numeros integrales con javascript en Facebook Twitter MySpace del.icio.us fresqui Meneame


Scripts Similares:

» reemplazar caracteres con javascript
» funcion isEmail javascript
» funcion isEmail javascript
» reemplazar string script
» trim javascript
» reemplazar string script
Ver el perfil de Gabriel Marcelo Rodriguez en LinkedIn

Privacidad ּ Publicidad ּ Prensa ּ Premios ּ Colaborar ּ Enlazarnos ּ Mapa del Sitio ּ Aviso legal ּ Boletín ּ Contacto
2001 - 2011 | Sitio Sitio creado y mantenido por Gabriel Marcelo Rodriguez
Hosting de alta calidad a bajo costo Neolo.com.ar