condition check for enter number would be betwen 0 to 9 0r decimal "."
i have a edit text box in which i can enter alphanumeric charracter but when i click the summit button then a checking would be perform for either edit text contains values 0 to 9 and also it can contain "." and in other case it will show a message that "pls enter numeric values" so how to achive it? means validate 0123456789 and "." in edit textbox
public void onClick(View arg0) {
String Am开发者_如何转开发mount =
((EditText) findViewById(R.id.price))
.getText().toString();
double db = Math.ceil(Integer.parseInt(Ammount)*100)/100;
ammount = Double.toString(db);
}};
Why to go hard just don't allow to enter string in your xml add:
<EditText
....
android:inputType="numberDecimal"
...
/>
add this tag in its xml android:numeric = "decimal"
One of the option would be use regex. Show the error message when validate
return false.
boolean validate(String s )
{
return s.matches("[0-9\\.]*");
}
精彩评论