Noticias Weblogs Foros Wiki Código

RecorteX

399 usuarios y 231 recortes de código
Usuario

Contraseña
Crear cuenta
8 Ajax asp csharp css fechas Flash html imagenes java javascript linux mysql oracle php sql SQLServer vbnet xhtml xml
Top Usuarios
fjmp76 (35)
albin (31)
josuebasurto (29)
juanjo (29)
pedrocaro (9)
stanz (8)
AndiXTRM (7)
Joserra (7)
miiglesi (6)
aplyca (5)
Top Etiquetas
php (38)
vbnet (27)
javascript (26)
html (25)
java (22)
sql (17)
csharp (16)
xml (13)
mysql (13)
css (10)
Flash (7)
imagenes (7)
xhtml (7)
linux (6)
asp (6)
fechas (6)
oracle (5)
SQLServer (5)
8 (4)
Ajax (4)

Aceptar determinados caracteres en un formulario html

Para que un campo de un formulario html solamente nos acepte determinados caracteres, tendriamos lo siguiente:

En el tag INPUT del html
 
 <input onKeyPress="return goodchars(event,'0123456789')" type="text" name="orden" size="2" value="">
 
Y en JAVASCRIPT, las siguientes funciones:
 
            function getkey(e) {
            if (window.event)
            return window.event.keyCode;
            else if (e)
            return e.which;
            else
            return null;
            }
    
            /* Caracteres validos */
            function goodchars(e, goods) {
            var key, keychar;
            key = getkey(e);
            if (key == null) return true;
 
            // get character
            keychar = String.fromCharCode(key);
            keychar = keychar.toLowerCase();
            goods = goods.toLowerCase();
 
            // check goodkeys
            if (goods.indexOf(keychar) != -1)
            return true;
 
            // control keys
            if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
            return true;
 
            // else return false
            return false;
            }
 
Identifícate para dejar un comentario.
info@recortex.com - Proyecto: Juanjo Navarro, 2006 - Diseño: Albin - Información legal y técnica