-
Validating Email Addresses in PHP
14 August 2012
Read moreA very quick snippet today because I've told two people to use this approach in the last few days and both of them told me they didn't know about it. How to check if an email address is valid in PHP: use one of the Filter functions, like this:
$email1 …
-
Simple Regular Expressions by Example
08 December 2011
Read moreWhenever I ask a group of developers if they are familiar with regular expressions, I seem to get at least half the responses along the lines of "I've used them, but I don't like them". Call me a geek if you like, but I quite like regex; I think often it seems unfriendly because it's used inappropriately or just thrown into code with "here be dragons" type comments rather than documentation about what should match, and what shouldn't!
As with most things, it's pretty easy when you know how, so here's my one-step-at-a-time approach to regex (stolen from my ZCE preparation tutorial slides). Let's begin at the very beginning: regular expressions have delimiters, usually a slash character, and these contain a pattern that describes a string.
pattern
notes
/b[aeiou]t/
Matches "bat", "bet", "bit", "bot" and "but" Also matches "cricket bat", "bitter lemon"