JavaScript - Funcion validar solo numeros

 
Vista:
sin imagen de perfil

Funcion validar solo numeros

Publicado por miguel (7 intervenciones) el 18/08/2014 16:32:35
Buenas mi duda es la siguiente tengo mi función validar números en JS en un texbox la cual obviamente solo me deja introducir números en el texbox pero quisiera añadirle también que solo me deje copiar y pegar números y no texto e aquí mi función :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function NumCheck(e, field) {
 
    //alert(e + " - " + field);
 
    key = e.keyCode ? e.keyCode : e.which
    // backspace
    if (key == 8) return true
    // 0-9
    if (key > 47 && key < 58) {
        if (field.value == "") return true
        regexp = /,[0-9]{2}$/
        return !(regexp.test(field.value))
    }
    // .
    if (key == 46) {
        if (field.value == "") return false
        regexp = /^[0-9]+$/
        return regexp.test(field.value)
    }
    // other key
    return false
 
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder