I need to perform the following check:
IF myString.contains()
ANY CHARACTERS OTHER THAN
letters a-z, A-Z, "_", "-", numbers 0-9
THEN .....
whats is the correct java syntax for such a check?
You could use a regular expression
Pattern badChar = Pattern.compile("[^A-Za-z0-9_-]");
if(badChar.matcher(myString).find()) {
// ...
}
This pattern will match any single character apart from letters, numbers, underscore and hyphen.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With