title: Android: Edit text validation for Currency
body: <p>I have a Edit-text in which user can enter amount, I want few limitations on Edit-text</p>
  
  <ol>
  <li>Amount can not be greater than 100000</li>
  <li>User enter amount up to two decimal places like 99999.50</li>
  </ol>
  
  <p><strong>-EDITED- Solved</strong></p>
  
  <p>How do I achieve this, do I have to create a <code>filter</code> or I can achieve it using <code>Regular Expression</code> in <code>myEdittext.addTextChangedListener(new TextWatcher() ...</code></p>
  
  <pre><code>myAmountEditText.addTextChangedListener(new TextWatcher() {
  
              @Override
              public void onTextChanged(CharSequence s, int start, int before, int count) {}
  
              @Override
              public void beforeTextChanged(CharSequence s, int start, int count,
                      int after) {}
  
              @Override
              public void afterTextChanged(Editable s) {
                if(amount!=null &amp;&amp; amount.length()&gt;=1 ){
                  if(amount.contains(".")){
                      int indexOFdec =  amount.indexOf(".");
  
                      if(indexOFdec &gt;=0) {
                         if(amount.substring(indexOFdec).length() &gt;3){
                             amount = amount.substring(0, amount.length()-1);
                             myAmountEditText.setText(amount);
                             myAmountEditText.setSelection(myAmountEditText.getText().length());
                         }
                      }
                  }
  
                  Double a = Double.parseDouble(amount.toString());
  
                  if(a&gt;0 &amp;&amp; a&lt;100000.00){
                      //my stuff
                  }else{
                      Toast.makeText(context, "amount greater than 100000", Toast.LENGTH_SHORT).show();
                  }
              }
          });
  </code></pre>