JavaFX 2.0 - Regex for Float in Text Field
935838Jun 22 2012 — edited Jun 22 2012Quick question, I am trying to add a regular expression that will only allow input of a float value.
Using
private final static String REG_EXP = "[-]?[0-9]+(\\.[0-9]+)?";
@Override public void replaceText(int start, int end, String text) {
if (text.matches(REG_EXP) || text.hashCode() == 0) {
super.replaceText(start, end, text);
}
}
When ever i enter say first char "-" the text.matches returns false. Even though i have this as optional within the regex? It will also not allow me to enter the decimal (.) Although ive trailed through the various java float examples for regex and this expression appears to be reoccur.
Could anyone advise what im doing wrong here?
Thanks