Skip to content

Instantly share code, notes, and snippets.

@ninux
Last active August 29, 2015 13:59
Show Gist options
  • Save ninux/10648411 to your computer and use it in GitHub Desktop.
Save ninux/10648411 to your computer and use it in GitHub Desktop.
using regex in java
private boolean containsNumbers(String s) {
Pattern p = Pattern.compile(".*\\d.*");
return p.matcher(s).find();
}
private boolean containsCharacters(String s){
Pattern p = Pattern.compile("[a-zA-Z]");
return p.matcher(s).find();
}
private boolean containsOneAt(String s){
int counter = 0;
Pattern p = Pattern.compile("[@]");
Matcher m = p.matcher(s);
while(m.find()){
counter++;
}
return counter == 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment