Hey all, so I'm trying to allow some text input which goes through a regex check before it's sent off. I want the text to only include A-Z, 0-9, and the space " " character. Here is my code now:
if(!title.matches("[a-zA-Z0-9_]+") {
//fail
}
else {
//success
}
However this still gives the //fail
result when I input something like "This is a test"
Any ideas? Thanks all.
You're not including the space in the Regex. Try the following:
if (!title.matches("[a-zA-Z0-9 ]+"))
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments