I need a function to display only numbers AND insert dot after three digits
<p>I am building a form, and I need a function to: display <code>###.###.###-##</code> I also need one to display <code>##.###.###-#</code> and another to display <code>#####-###</code></p>

<p>I managed to add a mask onkeypress to display the format I need, but still I cant figure out how to allow numbers only AND add the mask.</p>

<p>what I have:</p>

<pre><code> &lt;script language="JavaScript"&gt;

 function mascara(t, mask){
 var i = t.value.length;
 var saida = mask.substring(1,0);
 var texto = mask.substring(i)
 if (texto.substring(0,1) != saida){
 t.value += texto.substring(0,1);
 }
 }
 &lt;/script&gt;


&lt;form name="form"&gt;    
    &lt;fieldset&gt;

        &lt;label for="example"&gt;Example:&lt;/label&gt;
        &lt;input type="text" name="numbers" onkeypress="mascara(this, '###.###.###-##')" maxlength="14"&gt;

&lt;/fieldset&gt;
&lt;/form&gt;
</code></pre>
