Showing posts with label tools. Show all posts
Showing posts with label tools. Show all posts

October 12, 2009

Regex Pattern for Validating Email addresses

Interesting post here talks about how complex RFC 822 is, that defines a valid email address. But thankfully the guy found a simpler pattern from msdn and modified it to put more restriction on the regex; here it goes:-

"^([\w]+)(([-\.][\w]+)?)*@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"

However this pattern fails to approve email ids like "mygroup+subscribe@mygroups.com" which is a common pattern used by listserv email lists. There are few more cases when email bots send you emails containing reply to addresses like "mygroup+confirm-23EWEJEW233@mygroups.com" where you reply and using the session id "23EWEJEW233", your a/c is activated or something. Writely (now Google docs) uses a similar pattern allowing you to upload documents through emails; their email ids are of type "xyz+pqr-12345678901234567890-SDWEPO23@prod.writely.com"

To verify if a value is passing through this perl regex filter, i used the following command:
echo [candidate_value]|grep -P [pattern]
and then checking "echo $?", if its 0, the pattern matches, else it failed. Actually if the pattern matches, you will see the [candidate_value] printed as well.

Turns out adding support for '+' as additional symbol was the only thing required. The modified regex looks exactly the same, except one character "+" added in the sequence.

"^([\w]+)(([-\.\+][\w]+)?)*@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"
For ex:
  1. echo "abc.pp@fjdsf.sdsd.dsdsds.com"|grep -P "^([\w]+)(([-\.\+][\w]+)?)*@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"
    passes the regex
  2. echo   "abc.@fjdsf.sdsd.dsdsds.com"|grep -P "^([\w]+)(([-\.\+][\w]+)?)*@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"
    fails the regex
  3. echo "xyz+pqr-12345678901234567890-SDWEPO23@prod.writely.com"|grep -P "^([\w]+)(([-\.\+][\w]+)?)*@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"
    passes the regex

September 20, 2009

syntax highlighter for blogspot

as you might see now, i've the source highlighter plugin enabled. thanks to this post, it went really smooth this time.

July 30, 2009

Deleting all tables in a mysql database

Turned out there is no command like "trunk database " but unix piping could be a savior.

Warning: Somehow my putty session crashes after running the command mentioned below and i've to restart the session. Just in case you know a better way to do this, please do share in the comments. Thanks!

mysqldump -h <dbhost> -u <dbuser> -p --add-drop-table --no-data <dbname> | grep ^DROP | mysql -h <dbhost> -u <dbuser> -p <dbname>

June 27, 2009

10 Firefox plugins i use...

Just thought to create a handy list of the plugins i've been using at Y! I'll soon be moving to Mac (and probably in future migrations as well), this list will be really helpful in getting started fast.

  1. WebDeveloper - https://addons.mozilla.org/en-US/firefox/addon/60
  2. SwitchProxy - https://addons.mozilla.org/en-US/firefox/addon/125
  3. LiveHttpHeaders - http://livehttpheaders.mozdev.org/
  4. AdBlockPlus - http://adblockplus.org/en/installation
  5. Delicious - http://delicious.com/help/installff
  6. Smush!t - http://developer.yahoo.com/yslow/smushit/
  7. FoxyTunes - http://www.foxytunes.com/firefox/allversions.html
  8. FireBug - http://getfirebug.com/
  9. YSlow - http://developer.yahoo.com/yslow/
  10. JsonView - http://code.google.com/p/jsonview/

May 20, 2009

Javascript formatter

I was recently working on a webconsole for our product and turned out that my eclipse was somehow screwed up. It gave weird stacktraces whenever i tried formatting the javascript code. I thought of fixing the eclipse (for some reason, it didn't happen in first 15 minutes and i gave up :D) I searched and found a really interesting link which supported OO JS and formatted it really well. I'm impressed and thought i should share it with everybody (or least keep it handy for me).

Here is the URL: http://www.mobilefish.com/services/javascriptformatter/javascriptformatter.php