3 ms·
> What? You're going to hand code a lexer each time you need to parse a phone number or a zip code? If there was a better alternative we would be using it. STO
by bsder 6y ago
> What? You're going to hand code a lexer each time you need to parse a phone number or a zip code? If there was a better alternative we would be using it.
STOP PARSING WEB FORM INPUT. Please. For the love of God just stop.
This is why emails of the form "foo+bar@fakeaddress.myemail" rarely work. Somebody's regex didn't allow "+" and everybody copied it. If you really need to check an email address, send a verification email to it. It's the only method that actually works.
Why are you parsing a phone number. The user typed in a phone number, obey it. Are you sure that you know every combination of valid phone number?
Zip code ... maybe ... if you are US only. Otherwise a postcode can't be parsed either.
And this is before we talk about the Cardinal Sin of using regexes as parsers.
- Sohcahtoa82 6y ago> Zip code ... maybe ... if you are US only. Otherwise a postcode can't be parsed either. Also, don't store zip code as an integer. There are valid zip codes that start with zero that will likely get truncated if you store a zip code as an integer.