I'm trying to create a fairly simple regex to match some text and am having a difficult time with it. In this case, there's a single form field in which the user may enter a name or they may enter both a name and phone number. If it's the latter, I need to break the two pieces apart to persist them properly.
So, for example, the following bits of text would all be considered "valid" inputs:
So I'd like to write a little bit of code that would identify the middle two cases and tear them apart. I'm running under the assumption that no name will actually have a number in it so any numbers that appear will be a phone number. Also, the phone number will allways be entered last and with one space between the name and the phone number.
Here's what I originally created:
Unfortunately, that never matches anything, even if I'm using an input that I think it should match. So to
test if my regex was working, I changed it to just this:
For my input, I used "johnson 23412". This also fails to match.
What do I have screwed up here that my regexes don't seem to match anything, at all?
Thanks,
Corey