My server dev gave me a regex that he says is the requirement for user name. It is @"^\w+([\s-]\w+)*$"
I need help figuring out right Java expression for this. It is confusing since I need to put some escape characters to make compiler happy.
I am trying this. Please let me know if this is right :
Pattern p = Pattern.compile("^\\w+([\\s-]\\w+)*\\$", Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(username);
if ((username.length() < 3 ) || (m.find())) {
log ("Invalid pattern");
return false;
}
Is this correct ?