Commit 052697353f01fcc5d78ff69c022d4e9e96140a79

Authored by JLo'w
1 parent d7178ee7

Meilleur regex et gestion pour le champ prix

PremiereActivite/app/src/main/java/com/example/app_10p5/DecimalDigitsInputFilter.java
@@ -14,15 +14,22 @@ public class DecimalDigitsInputFilter implements InputFilter { @@ -14,15 +14,22 @@ public class DecimalDigitsInputFilter implements InputFilter {
14 Pattern mPattern; 14 Pattern mPattern;
15 15
16 public DecimalDigitsInputFilter(int digitsBeforeZero,int digitsAfterZero) { 16 public DecimalDigitsInputFilter(int digitsBeforeZero,int digitsAfterZero) {
17 - mPattern= Pattern.compile("[0-9]{0," + (digitsBeforeZero-1) + "}+((\\.[0-9]{0," + (digitsAfterZero-1) + "})?)||(\\.)?"); 17 + mPattern = Pattern.compile("(0|[1-9][0-9]{0,2})?([,.][0-9]{0,2})?");
  18 +
18 } 19 }
19 20
20 @Override 21 @Override
21 public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { 22 public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
22 23
23 - Matcher matcher=mPattern.matcher(dest);  
24 - if(!matcher.matches())  
25 - return ""; 24 + String result =
  25 + dest.subSequence(0, dstart)
  26 + + source.toString()
  27 + + dest.subSequence(dend, dest.length());
  28 +
  29 + Matcher matcher = mPattern.matcher(result);
  30 +
  31 + if (!matcher.matches()) return dest.subSequence(dstart, dend);
  32 +
26 return null; 33 return null;
27 } 34 }
28 35