I have a form in Php and I want an input box field to allow to paste numeric characters but to restrict letters

0

I have a form in Php and I want an input box field to allow to paste numeric characters (ctrl-c followed ctrl-v) but to restrict letters (the field must only allow numbers either by typing (onkeypress) or by pasting data from another source :

<input name="telefono" type="text" id="telefono" placeholder="telefono" tabindex="3" title="Telefono">

This is the script:

<script>
function Numeros(string){//Solo numeros
    var out = '';
    var filtro = '1234567890';//Caracteres validos

    //Recorrer el texto y verificar si el caracter se encuentra en la lista de validos 
    for (var i=0; i<string.length; i++)
       if (filtro.indexOf(string.charAt(i)) != -1) 
             //Se añaden a la salida los caracteres validos
         out += string.charAt(i);

    //Retornar valor filtrado
    return out;
} 

</script>
    
asked by Eduardo Vizcarra 21.02.2018 в 16:01
source

0 answers