0

I'm using some regex to validate an EditText and am trying to ensure that a user won't enter a space/whitespace. My current regex is: "^[A-Za-z0-9][\\w.-]+$";

Does anyone have any idea? I did a little research and discovered adding in \\s detects spaces but it didn't help.

Thanks for any help!

Connor McFadden
  • 441
  • 1
  • 4
  • 20

3 Answers3

0

If you want to have your regex matching only when the string doesn't contain any spaces you can try:

^[^\s]*$
Giovanni
  • 543
  • 2
  • 11
0

Are you searching for ^[^\\s]*

Vijeesh
  • 181
  • 10
0

Try this:

^[\S]*$

\S matches any non-whitespace character.

trivelt
  • 1,913
  • 3
  • 22
  • 44