none
so string

תשובות

  • Boa tarde conheço Dois metodos:

    1- Por meio do VB.NET:

     

     

    Private Sub TxtSize_KeyDown(ByVal sender As ObjectByVal e AsSystem.Windows.Forms.KeyEventArgs) Handles TxtImagemLargura.KeyDown
    
        'Se o character não for numérico ou backspace, ignorar o que foi digitado
        If Not IsNumeric(Chr(e.KeyCode)) And e.KeyCode <> 8 Then
            e.SuppressKeyPress =  True 
        End If
    
    End Sub
    

    2- Por meio de JavaScript

     

    //tam = Tamanho do campo
    
    //fld = input
    
    //e = evento
    
    function ConsisteNumerico(tam, fld, e) {
    
      var key = '';
    
      var i = 0;
    
      var len = 0;
    
      var strCheck = '0123456789';
    
      var aux = '';
    
      var whichCode = (window.Event) ? e.which : e.keyCode;
    
      if (whichCode == 13 || whichCode == 8 || whichCode == 0)
    
        return true; // Enter
    
      key = String.fromCharCode(whichCode); // Get key value from key code
    
      if (strCheck.indexOf(key) == -1)
    
        return false; // Not a valid key
    
      len = tam -1;
    
      aux = '';
    
      for(; i < len; i++)
    
        if (strCheck.indexOf(fld.value.charAt(i))!=-1)
    
          aux += fld.value.charAt(i);
    
      aux += key;
    
      fld.value = '';
      fld.value += aux;
      return false;
    
    
    <span style="font-family:Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace; font-size:13px; line-height:14px; white-space:normal"><code style=""><</code><code style="">input</code> <code style="">type</code><code style="">=</code><code style="">"text"</code> <code style="">size</code><code style="">=</code><code style="">"5"</code> <code style="">name</code><code style="">=</code><code style="">"testeNumerico"</code><code style="">onKeyPress</code><code style="">=</code><code style="">"return(ConsisteNumerico('5',this,event))"</code> <code style="">value</code><code style="">=</code><code style="">""</code><code style="">/></code></span>
    
    <span style="font-family:Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace; font-size:13px; line-height:14px; white-space:normal"><code style=""> para chamar o evento...</code></span>
    
    Se for útil marque.

     

     

     


    Se for útil marcar como resposta Para facilitar a busca de outros.
    • הוצע כתשובה על-ידי Jucinei Pereira יום רביעי 17 אוגוסט 2011 16:57
    • סומן כתשובה על-ידי Rogerio JerezOwner יום חמישי 01 ספטמבר 2011 19:09
    יום רביעי 17 אוגוסט 2011 16:56

כל התגובות

  • Amigo, pra qual linguagem você quer fazer essa validação?

    "Mas a persistência é o que leva a perfeição." - Se a resposta for útil, marque-a. Poderá ser útil para outros desenvolvedores.
    יום רביעי 27 יולי 2011 19:48
  • Boa tarde conheço Dois metodos:

    1- Por meio do VB.NET:

     

     

    Private Sub TxtSize_KeyDown(ByVal sender As ObjectByVal e AsSystem.Windows.Forms.KeyEventArgs) Handles TxtImagemLargura.KeyDown
    
        'Se o character não for numérico ou backspace, ignorar o que foi digitado
        If Not IsNumeric(Chr(e.KeyCode)) And e.KeyCode <> 8 Then
            e.SuppressKeyPress =  True 
        End If
    
    End Sub
    

    2- Por meio de JavaScript

     

    //tam = Tamanho do campo
    
    //fld = input
    
    //e = evento
    
    function ConsisteNumerico(tam, fld, e) {
    
      var key = '';
    
      var i = 0;
    
      var len = 0;
    
      var strCheck = '0123456789';
    
      var aux = '';
    
      var whichCode = (window.Event) ? e.which : e.keyCode;
    
      if (whichCode == 13 || whichCode == 8 || whichCode == 0)
    
        return true; // Enter
    
      key = String.fromCharCode(whichCode); // Get key value from key code
    
      if (strCheck.indexOf(key) == -1)
    
        return false; // Not a valid key
    
      len = tam -1;
    
      aux = '';
    
      for(; i < len; i++)
    
        if (strCheck.indexOf(fld.value.charAt(i))!=-1)
    
          aux += fld.value.charAt(i);
    
      aux += key;
    
      fld.value = '';
      fld.value += aux;
      return false;
    
    
    <span style="font-family:Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace; font-size:13px; line-height:14px; white-space:normal"><code style=""><</code><code style="">input</code> <code style="">type</code><code style="">=</code><code style="">"text"</code> <code style="">size</code><code style="">=</code><code style="">"5"</code> <code style="">name</code><code style="">=</code><code style="">"testeNumerico"</code><code style="">onKeyPress</code><code style="">=</code><code style="">"return(ConsisteNumerico('5',this,event))"</code> <code style="">value</code><code style="">=</code><code style="">""</code><code style="">/></code></span>
    
    <span style="font-family:Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace; font-size:13px; line-height:14px; white-space:normal"><code style=""> para chamar o evento...</code></span>
    
    Se for útil marque.

     

     

     


    Se for útil marcar como resposta Para facilitar a busca de outros.
    • הוצע כתשובה על-ידי Jucinei Pereira יום רביעי 17 אוגוסט 2011 16:57
    • סומן כתשובה על-ידי Rogerio JerezOwner יום חמישי 01 ספטמבר 2011 19:09
    יום רביעי 17 אוגוסט 2011 16:56