06.09.06

Mommy, Wow! I’m a Big Boy Now!

Posted in Development at 3:56 pm by Soabirw

Despite being a programmer for such a long time, I still haven’t been able to get comfy with regular expressions. I know they are very powerful and can solve your validation woes lickity split (and that’s no shit), but good gravy that is some cryptic jarble. When trying to validation some international phone numbers, I.E. “+555.55555555555×555″, it was actually getting silly with how many various explosions and manual checks I was having to do. So I buckled down and managed to write this:

‘^[+]([0-9]{1,3})[.]([0-9]{1,12})([x]([0-9]{1,4}))?$’

No Google action or anything. That’s 90% from my keister, right there. I did read the first few pages of the O’Reily book though. Literally this means “First I expect the beginning of a line, followed by one + character, followed by 1 to 13 characters of 0-9, then followed by a dot, then followed by 1 to 12 chatacters of 0-9, then optionally a x followed by 1 to 4 characters of 0-9, then an end of the line.”

I can’t wait until PHP has a strtoregex() function just like strtotime(). So I can type that big sentence up there and it will magically make my regular expression. ;)

Comments are closed.