PDA

View Full Version : Parsing strings - best method?


JustAnotherDude
10-23-07, 19:37
If a user enters more than one email address in a form field, what's best way to only allow the first one?

I thought about using explode, but the code I came up with seems rather inefficient, because the user may enter the data with "comma" between the addresses, or with "semicolon" between the addresses, and with or without whitespace between the addresses.

Suggestions greatly appreciated.
Thanks!

noahawk
10-24-07, 17:56
I'm thinking maybe accept the input and then look to see where the first space, comma, semicolon, etc. occurs and then take the substring from the beginning until just before that spot?

JustAnotherDude
10-24-07, 18:32
Thanks for your response.
What you suggest is pretty much what I'm doing, except it takes me 4 lines of code (I've barely scratched the surface of PHP, so have a LOT to learn yet). Was thinking there's probably a better way.

noahawk
10-27-07, 12:39
I don't know of any other way, but that doesn't mean there isn't. You could use dropdown boxes for the .com,.net,.org, but now with the proliferation of top level domains with email addresses, it may be hard to keep the list updated. But that is a surefire way to limit them to one address.