-3

I am getting an address string from the client (first I check that it is a string under a certain length), and I have this so far: ^[a-zA-Z0-9 ]+$ but it will fail if the address has a "." char in it.

I want a single regex that also matches if a "." char shows up: the address can only contain spaces, numbers and letters.

Obviously, one can do if "." in address_string, but I am trying to do my check in one regex match.

How do I also escape/search for a "." char in a string?

  • Add `\.` to your regex: `^[a-zA-Z0-9\. ]+$` Of course this will allow things like `a..........b`, which maybe you don't really want. – John Gordon Oct 17 '19 at 15:57

1 Answers1

-1

Just put in an escape character:

^[a-zA-Z0-9 \.]+$
RightmireM
  • 2,381
  • 2
  • 24
  • 42