Been struggling with a regexp using perl since I couldn't get sed to work as I wanted (mainly "+" sucks with sed).
Perl 5.8.8 sucks, or the lack of Perl 5.10 on my box sucks! Really
7 deadly sins of regexp
Lust /(.*?)/
Gluttony /(.{1,})\b/
Greed /^.*$/
Sloth http://www.amazon.com/Regular-Expression-Pocket-Reference-Expressions/dp/0596514271/ref=pd_bbs_sr_2?ie=UTF8&s=books&qid=1229670757&sr=8-2
Wrath s/.*//g
Envy FUCK IT!
Pride /(\((?:[^()]++|(?-1))*+\))/
validating user names sucks!
You know when you're writing any application, and you want to restrict the characters in the user name? Instead of checking for non allowed characters, look for allowed. Sounds strange? Not really, you'll understand:
function checkname($string, $allowed) { $allowed = "/[$allowed]/s"; $string = preg_replace($allowed, "", $string); if ( $string ) return FALSE; else return TRUE; }
So what you'll do is remove all allowed characters, and if there are any left in the string the user has chosen an invalid username. Ofcourse it's regexp that does the trick. Using the code:
if ( ! checkname($input, "A-Za-z0-9_\.") ) echo "Invalid username!"; else echo "Ok, lets go!
We're allowing A-Z, a-z, 0-9, underscore and dots in the username.
Tags
Apple Arlanda Audiobooks Canada Code Poetry England faac Firefox first post Heatrow iPhone iPod iTunes Javascript job Links Linux London Mac mdadm Montreal mpg321 MySQL Named Capture Netbook On the plane pacemaker PC Perl PHP Picture RAID Reading RegExp Server Stockholm Sucks! (Really!) Sundsvall Sweden Tips Travel Traveling tv.autopsy.se Unix WordpressDemoscene
projects
Categories
Twitter
Error: Twitter did not respond. Please wait a few minutes and refresh this page.