Jump to content

[Resolvido] Caixa de texto


Whiteangel
 Share

Recommended Posts

Boas pessoal,

Tenho uma dúvida , como posso definir uma caixa de texto a receber só números (digitar ex: nº de telm), caso digite letras apareça uma mensagem de erro???

<label for="pesquisa1">Telf/Telm:</label>

<input type="text" name="telefone" id="telefone" maxlength="9" size="13" />

Link to comment
Share on other sites

Com javascript.

Um exemplo:

function ApenasNumero(e){
   var tecla=(window.event)?event.keyCode:e.which;  
   if((tecla>47 && tecla<58)) return true;
   else{
 if (tecla==8 || tecla==0) return true;
else  return false;
   }
}

<input onkeypress='return SomenteNumeroEmais(event)' type="text" id="teste">

Estranha forma de vida que tem a capacidade de transformar comandos em mensagens de erro.

ndsotware.org

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.