Question

I want to replace the value in an editText if user enter two decimal points by mistake

 else if(txtLdays.getText().toString().trim().contains(".."))
             {


                txtLdays.requestFocus();    
                txtLdays.setError("Double decimal ?");  

             // something like this
               ??   txtLdays.replaceWith(".." , ".");

                 return false;
             }
Was it helpful?

Solution

Use String#replaceAll() and match the . more than one times in the string.

 txtLdays.setText(txtLdays.getText().toString().replaceAll("([\\.]{2,})", "."));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top