Back to project page android-edittext-validator.
The source code is released under:
MIT License
If you think the Android project android-edittext-validator listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.andreabaccega.formedittextvalidator; // w w w. jav a 2 s .c o m import android.widget.EditText; /** * A validator that returns true only if the input field contains only numbers * and the number is within the given range. * * @author Said Tahsin Dane <tasomaniac@gmail.com> * */ public class NumericRangeValidator extends Validator{ private int min, max; public NumericRangeValidator(String _customErrorMessage, int min, int max) { super(_customErrorMessage); this.min = min; this.max = max; } public boolean isValid(EditText et) { try { int value = Integer.parseInt(et.getText().toString()); return value >= min && value <= max; } catch(NumberFormatException e) { return false; } } }