Parsing strings - best method?

Discussion in 'Software' started by JustAnotherDude, Oct 23, 2007.

  1. JustAnotherDude

    JustAnotherDude Private E-2

    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!
     
  2. noahawk

    noahawk Corporal

    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?
     
  3. JustAnotherDude

    JustAnotherDude Private E-2

    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.
     
  4. noahawk

    noahawk Corporal

    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.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds