I have a numberDecimal EditText which I want to validate using a regular expression. In validation what I want is:
Before the decimal point, th
I tried your pattern using my code as following. It works perfectly as 2.1, 32.5, 444.8, 564.9 etc.
My code:
public class WebPush extends Activity {
EditText editTxt;
private TextView regresult;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
editTxt = (EditText) findViewById(R.id.editID);
regresult = (TextView) findViewById(R.id.txtID);
String urName = editTxt.getText().toString();
editTxt.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,int arg3) {
}
@Override
public void afterTextChanged(Editable s) {
if (editTxt.getText().toString().matches("(^([0-9]{0,3})?)(\\.[0-9]{0,1})?$"))
{
regresult.setText("");
}
else
{
regresult.setText("invalid number");
}
}
});
}
}