Just a quick post before I leave. During the holiday season, I managed to study some regular expression and come up with few lessons learned. A good start for a regex newbie like me.
Creating code name from text
I’m creating a simple store application and I want to create automatically an item code based on the given item name (only when the user does not enter a code). Here is the regex:
preg_replace('/[^-a-zA-Z0-9]/', '', $name);
Simple amount validation
^[0-9]+(\.[0-9][0-9])?$ # which will match dddd.dd or dddd
That’s it for now.