Bonjour,
j'essai de faire des filtres pour des edittext mais c'est le truc que je ne comprends absolument pas.
J'aimerai faire un filtre de ce format : hh:ss-hh:ss
J'ai fais ceci :
même si j'entre 02:30-04:40, je n’atteins pas le Log, j'imagine que le pattern n'est pas bon...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 private boolean checkSyntaxTs(String timestamp) { boolean isValid = false; if (timestamp.isEmpty() || timestamp.equals("")) return true; String expression = "^[0-9]{2}:[0-9]{2}-[0-9]{2}:[0-9]{2}$"; Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(timestamp); if (matcher.matches()) { Log.w("format", "match"); //n'atteins jamais ce point String[] periode1 = timestamp.split("-"); String[] periode1bis1 = periode1[0].split(":"); String[] periode1bis2 = periode1[1].split(":"); int hh1 = Integer.parseInt(periode1bis1[0]); int hh2 = Integer.parseInt(periode1bis2[0]); int mm1 = Integer.parseInt(periode1bis1[1]); int mm2 = Integer.parseInt(periode1bis2[1]); if (hh1 < hh2) { if (hh2 < 24) isValid = true; } else if (hh1 == hh2) { if (mm1 < mm2) { if (mm2 < 60) isValid = true; } } } return isValid; }
Quel serait donc le bon pattern svp ?
Cordialement.
Partager