1 Reply Latest reply on May 14, 2013 2:52 AM by Muppet Mark

    Regex - Limit input to a positive number (float or int)

    Petfactory

      Hi!

       

      I wish to limit the user input of and edittext to only allow a positive number, float or int. I do not yet know my Regex good enough to do this. I realize that I must get better at regex but in the meantime does any one know how to do this ?

       

      I have used this so far on the edittext:

       

      function checkTextInput() 
      { 
          if (this.text.match(/[^0-9.]/g)) 
          { 
              this.text = this.text.replace(/[^0-9.]/g, ""); 
          }  
      }
      
      

       

      Which matches

      000.0001

      0.45.000.1

      ...1

      which is not desired.

       

      Desired is

      0.n

      .n

      n.n

       

      Best Regards,

      Johan