-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added FloatNumericRangeValidator, refactored some code
- Loading branch information
Showing
6 changed files
with
149 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
library/src/com/andreabaccega/formedittextvalidator/FloatNumericRangeValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.andreabaccega.formedittextvalidator; | ||
|
||
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 FloatNumericRangeValidator extends Validator{ | ||
|
||
private int min, max; | ||
|
||
public FloatNumericRangeValidator(String _customErrorMessage, int min, int max) { | ||
super(_customErrorMessage); | ||
this.min = min; | ||
this.max = max; | ||
} | ||
|
||
public boolean isValid(EditText et) { | ||
try { | ||
double value = Double.parseDouble(et.getText().toString()); | ||
return value >= min && value <= max; | ||
} catch(NumberFormatException e) { | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.