Archive for the ‘Web Development’ Category

Uncommon Regular Expressions That Should Be

For some strange reason I was recently surprised to find that regexes that should be common were no where to be found inside the interweb.  So here they are.

This is a Regex for an IP address:

^(?:(?:25[0-5]|2[0-4]\d|[1]\d\d?|[1-9]\d?|[0])\.){3}(?:25[0-5]|2[0-4]\d|[1]\d\d?|[1-9]\d?|[0])$

Notice that it does use those fancy extensions which have a wonderful description in the python documentation for the regular expression module named re.  This allows only IP addresses that would be valid in a bind zone file (my reason for needing this regex). That is it dissallows any number higher than 255 in any octet and does not allow zeros to lead any of the octets — an important oversight in many IP address regexes in the web.

And here is a regex for a fully qualified domain name:

^(?:(?!-)[a-zA-Z0-9]+(?:-+[a-zA-Z0-9]+)*\.)+[a-zA-Z]{2,4}\. $

This is for fully qualified domain names based on RFC 952 and 1123. Meaning that we do not allow any underscores inside the domain name or any of the other slack rules that were introduced in 2181. Also the GTLDs change enough (and they are making it easier to create new GTLDs) that it is futile to try limiting the top level domain with a regex. If you really want to know if the domain name is valid then resolve it yourself — I just want to know that it is in a valid format. For more information on valid names check out this link.

I have used these regular expressions in Python, Javascript and PHP, but they should work pretty much anywhere as long as the extensions are supported.

Tags:

No Comments


Slow Push Navigation Button

This is as much informative as it is an archive so that I will remember how to create this again. This will make a fancy navigation bar with buttons that will transform slowly when the mouse is hovering over them. It creates a neat effect that button is being pressed and this could be extended so that when you click it transforms the button again making it look like it is being pushed into the screen. As opposed to some other navigation menus that require a new image be made for each menu item (the text being part of the image) this navigation bar will use a normal anchor with text node for the link text. Here is a live example of the navigation bar.

Read the rest of this entry »

No Comments



SetPageWidth