Salut,
Mon but est de faire une regexp sachant que je débute en java (depuis vendredi).
Le code à changer est:
Code:
Code :
- String pwd = user.getPasswd();
- int i = 0;
- int count = 0;
- int n = pwd.length();
- int ch;
-
- while (i < n)
- { ch = (int)pwd.charAt(i);
- if ((ch >= 0x00 && ch <= 0x2C) ||
- (ch >= 0x2E && ch <= 0x2F) ||
- (ch >= 0x3A && ch <= 0x3F) ||
- (ch >= 0x5B && ch <= 0x5E) ||
- (ch == 0x60) ||
- (ch >= 0x7B)) {
- count = 1 ;
- break ;
- }
- i++;
- }
|
Terrible, non ?
Donc, si j'ai bien compris la doc, il me faut créer un pattern contenant l'expression puis faire un matches avec ce pattern sur la string à checker.
Voici mon code (qui marche pas!):
Code:
Code :
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- [...]
- private boolean LoginOk ;
- [...]
- pattern = Pattern.compile("a-zA-Z0-9_.-@]{*}" );
- LoginOk = matches(pattern) ;
- if(LoginOk) {
- [...]
- }
|
1/ Pattern, c une variable de quel type ? comment la créer ?
2/ L'expression est-elle correct pour // Only Characters [a-z], [A-Z], [.], [0-9], "@", "_" and "-" are authorized.
En PHP, je crois que ce serait bon.
Merci.
C'est bon:
Code :
- return user.getLogin().matches("a-zA-Z0-9.@_-]" ) ;
|
Message édité par cult le 10-05-2004 à 11:05:07