I got a web application and an Android app in which I want to check the input.
Now I created this Regex in Java:
private static final String NAME_REGEX = "^[\\w ]+$";
if (!Pattern.matches(NAME_REGEX, name)) {
mNameView.setError(getString(R.string.error_field_noname));
focusView = mNameView;
cancel = true;
}
In JavaScript I want to test the same so I used:
var re = /^[\w ]+$/;
if (!re.test(company)) {
...
}
Everything works fine except that the Java version accepts the characters ä,ö,ü, ó, á (...) and the JavaScript version won't.
Don't know where's the difference between the code mentioned above?
In the end the most important thing is that both (JavaScript and Java) work exactly the same.
Goal:
Get a regex for Javascript that is exactly the same as in Java (^[\\w ]+$)