I am having some trouble trying to figure out how to parse information collected from user. The information I am collecting is:
- Age
- Sex
- Zip Code
Following are some examples of how I may receive this from users:
- 30 Male 90250
- 30/M/90250
- 30 M 90250
- M 30 90250
- 30-M-90250
- 90250,M,30
I started off with explode function but I was left with a huge list of if else statements to try to see how the user separated the information (was it space or comma or slash or hypen)
Any feedback is appreciated.
Thanks
It’s easy enough. The ZIP code is always 5 digits, so a simple regex matching
/\d{5}/will work just fine. The Age is a number from 1 to 3 digits, so/\d{1,3}/takes care of that. As for the gender, you could just look for anfforfemaleand if there isn’t one assumemale.With all that said, what’s wrong with separate input fields?