Sunday, July 13, 2008

Regular Expressions for username, date, ip address, color, postal code, and phone

Pasting here just to reuse them in the near future.

Here are eight examples of practical PHP regular expressions and techniques that I've used over the past few years using Perl Compatible Regular Expressions. This guide goes over the eight different validation techniques and describes briefly how they work. Usernames, telephone numbers, email addresses, and more. Here are eight examples of practical PHP regular expressions and techniques that I've used over the past few years using Perl Compatible Regular Expressions. This guide goes over the eight different validation techniques and describes briefly how they work. Usernames, telephone numbers, email addresses, and more.

Validating Usernames

Something often overlooked, but simple to do with a regular expression would be username validation. For example, we may want our usernames to be between 4 and 28 characters in length, alpha-numeric, and allow underscores.
$string = "userNaME4234432_";
if (preg_match('/^[a-z\d_]{4,28}$/i', $string)) {
echo "example 1 successful.";
}

Validating Telephone Numbers

A much more interesting example would be matching telephone numbers (US/Canada.) We'll be expecting the number to be in the following form: (###)###-####
$string = "(032)555-5555";
if (preg_match('/^(\(?[2-9]{1}[0-9]{2}\)?|[0-9]{3,3}[-. ]?)[ ][0-9]{3,3}[-. ]?[0-9]{4,4}$/', $string)) {
echo "example 2 successful.";
}

Thanks to Chris for pointing out that there are no US area codes below 200.

Again, whether the phone number is typed like (###) ###-####, or ###-###-#### it will validate successfully. There is also a little more leeway than specifically checking for enough numbers, because the groups of numbers can have or not have parenthesis, and be separated by a dash, period, or space.

Email Addresses

Another practical example would be an email address. This is fairly straightforward to do. There are three basic portions of an email address, the username, the @ symbol, and the domain name. The following example will check that the email address is in the valid form. We'll assume a more complicated form of email address, to make sure that it works well with even longer email addresses.
$string = "first.last@domain.co.uk";
if (preg_match(
'/^[^0-9][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[@][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{2,4}$/',
$string)) {
echo "example 3 successful.";
}

Postal Codes

Validating Postal codes (Zip codes?,) is another practical example, but is a good example to show how ? works in regular expressions.

$string = "55324-4324";
if (preg_match('/^[0-9]{5,5}([- ]?[0-9]{4,4})?$/', $string)) {
echo "example 4 successful.";
}

What the ? does in this example is saying that the extra 4 digits at the end can either not exist, or exist- but only once. That way, whether or not they type them in, it will still validate correctly.

IP Addresses

Without pinging or making sure it's actually real, we can make sure that it's in the right form. We'll be expecting a normally formed IP address, such as 255.255.255.0.
$string = "255.255.255.0";
if (preg_match(
'^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:[.](?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$',
$string)) {
echo "example 5 successful.";
}

Hexadecimal Colors

Moving right along with numbers, we could check for Hexadecimal color codes, in short hand or long hand format (#333, 333, #333333 or 333333) with an optional # symbol. This could be useful in a lot of different ways... maybe previewing CSS files? Grabbing colors off pages? The options are endless.
$string = "#666666";
if (preg_match('/^#(?:(?:[a-f\d]{3}){1,2})$/i', $string)) {
echo "example 6 successful.";
}

Multi-line Comments

- A simple way to find or remove PHP/CSS/Other languages multi-line comments could be useful as well.
$string = "/* commmmment */";
if (preg_match('/^[(/*)+.+(*/)]$/', $string)) {
echo "example 7 successful.";
}

Dates

- And my last simple, yet practical example would be dates, in my favorite MM/DD/YYYY format.
$string = "10/15/2007";
if (preg_match('/^\d{1,2}\/\d{1,2}\/\d{4}$/', $string)) {
echo "example 8 successful.";
}



The source is here.

Tuesday, July 8, 2008

firefox 3.0 crashes

As soon as Firefox 3.0 have been officially released, i downloaded and installed it. But i have many complains on this new version. It consumes more than 50% resources on PC, and crashed 3-5 times a day. Especially when working with heavy ajax applications like Google Spreadsheet, or similar. I have sent multiple crash reports to Firefox team, and hoping that they are working on it.

Planning to move back to FF 2.0

Sunday, July 6, 2008

Outsource your Symfony and Zend framework applications

It is been quite long time since we have chose Symfony and Zend framework as a PHP5 development. I was wondering how we were developing using plain PHP. It was all pain! The only best way was to create our custom framework and use it on all projects. These frameworks are the best practice and result of what PHP developers used in the past to create their web applications. We now focused on the web application outsourcing under the company Singleton LLC, which i founded a year ago. Our team is now capable of building small to medium sized web applications using these framework. Having developed tens of projects, we now see that we should really be different from other teams in India, or Pakistan. We should develop in such a way not to earn money in a shortest time, but to work in a detail-oriented ways to deliver what customer exactly wished. To deliver running application is not the final result, and it shouldn't be the outsourcing goal even for small teams like us. So we really focused on details, and comminication. We understood that we need more than just a coding.

On the other side, the are buyers who wish to have their software codes in a cheapest and shortest way, while the others are looking for someone who can implement their ideas in quite cheap but qualified way. We'd rather to work with the companies who are looking for qualified team, but the quite reasonable price. Our aim is not to become the cheaper than others, but more qualified.

If you are looking for a responsive and responsible team to implement your ideas into real life, we are available for hire. You can outsource your Symfony and Zend Framework projects to us.

Thanks,
Bayar

Wednesday, April 30, 2008

Useful articles and links 5

  • Free Admin Template For Web Applications
    It is a 3 column design with a tabbed menu. The idea is having the standard categories in the tab menu for an easy reach and have all the detailed ones in the left menu. And there is an info box at the right to inform users what’s going on at that page. You can customize it however you want to fit your project. It has a listing and a new entry sample which covers %99 of an admin screen.
  • Lightweight JavaScript Accordion with CSS
    The JavaScript accordion above is 1.65 kilobytes when packed. If you have a small project that could use an accordion and don’t want to include an entire JavaScript framework to do the job then give this script a try.
  • 5 PHP 5 features you can't afford to ignore
    There are dozens of reasons to switch to PHP 5—not least the fact that, if you're still stuck on PHP 4, the PHP team is about to pull the rug from under your feet. Despite the fact that you may not have a choice in the matter, upgrading comes with a number of bonus new features that can help you write better code and gain access to new functionality that required a fair amount of hacking in previous version. Here's a quick list of 5 personal favourites
  • 30+ Unusually Awesome Freshly Created Designs
    Today we got you some incredibly awesome website designs that is freshly created with unique ideas, graphics and layouts.

Monday, April 28, 2008

Useful articles and links 4

  • Build custom templates for your data-driven Web sites
    Most developers dread dealing with HTML tables and cells to build their Web sites. For one thing, tables make it difficult to modify the site later or to change its appearance. Discover some basic techniques for writing Web sites that you can later re-skin by using templates during the site's initial creation. Also, learn why you should use data-driven techniques for your own Web sites.
  • 30 Exceptional CSS Techniques and Examples
    In this article, I’ve pieced together 30 excellent CSS techniques and examples that showcases the capabilities and robustness of CSS. You’ll see a variety of techniques such as image galleries, drop shadows, scalable buttons, menus, and more - all using only CSS and HTML.
  • Interview with Donald Knuth
    Andrew Binstock and Donald Knuth converse on the success of open source, the problem with multicore architecture, the disappointing lack of interest in literate programming, the menace of reusable code, and that urban legend about winning a programming contest with a single compilation.
  • So long TextMate?... Hello NetBeans? Really? Yeah, really.
    I'll admit it, I'm one of many folks that used to treat NetBeans as a whipping boy. Questioning why Sun would bother dumping money into the horse that so obviously lost the race to Eclipse and IntelliJ to win the hearts and minds of Java developers around the world.
  • Build a customizable RSS feed aggregator in PHP
    You'll appreciate this article's fully functional PHP code snippets, demonstrating the use of PHP-based server-side functions to develop a customizable RSS feed aggregator. In addition, you'll reap instant benefits from using the fully functional RSS feed aggregator code, which you can download from this article.
  • Here’s the list of some websites that are offering website screenshots services which you can use if you are planing to start a web gallery for example.
  • jThumb dynamically wraps images and/or link images with a div. You can add them an specific size (width and height) inside the css file. And optionally it can automatically center the image inside the frame.
  • You may have seen recent reports that have surfaced stating that web sites running on Microsoft’s Internet Information Services (IIS) 6.0 have been compromised. These reports allude to a possible vulnerability in IIS or issues related to Security Advisory 951306 which was released last week.
  • It’s time to upgrade your Rails 2.0 application with user authentication, and we hear that RESTful Authentication is the way to go, but all the instructions out there (even on the plugin repository sites) are out of date or don’t completely work or only work on Rails 1.2.x. In this tutorial, however, we’ll go step-by-step to install a complete RESTful authentication suite with all the trimmings your advanced Rails 2.0 application requires. Best of all, we’ll maintain complete control of our user administration code instead of relying on 3rd party and/or outdated software.

Monday, April 21, 2008

IT Outsourcing Job Trends

On oDesk, there is new part that could be very useful for us. If you plan to learn new technology, you can make your decision easily after you see the trends on oDesk Job Posts. As you see there Visual Basic is going down while Rails is going up. It means you better start learning Rails instead of Visual Basic ;)
Here you go; http://www.odesk.com/trends

Tuesday, April 15, 2008

7 days tutorial of Symfony 1.1

With the completion of the new Symfony 1.1 framework, there are many changes in store for the average Symfony developer. Some less visible changes in the framework include a refactoring of the core classes to increase modularity. The largest change, by far, is in the handling of forms, validation, and the helper system. During the next seven days, we'll be covering the new approach to Symfony forms and validation. The new solution is a MAJOR improvement over the old system- it will allow for faster development and greater control. Gone are the days of mindless form generation. The new system isn't perfect, but it's definitely worth your time.
Other symfony related posts from Thatsquality.com

Sunday, April 13, 2008

Useful articles and links 3

  • Google Code University
    This website provides tutorials and sample course content so CS students and educators can learn more about current computing technologies and paradigms. In particular, this content is Creative Commons licensed which makes it easy for CS educators to use in their own classes. The Courses section contains tutorials, lecture slides, and problem sets for a variety of topic areas:
    • AJAX Programming
    • Distributed Systems
    • Web Security
    • Languages
  • 10 JavaScript Effects to Boost Your Website’s Fanciness Factor
    Here’s a collection of 10 powerful – yet easy-to-implement — JavaScript effects to supplement your web page’s interface. These were picked using a “bang for your buck” methodology; meaning that these effects were chosen specifically because they provide high-impact effects with very little effort in installing and using them.
  • 10 things IT needs to know about Ajax
    The introduction of any new Web technology will affect a network's infrastructure in ways that range from inconsequential to earth shattering. Ajax is one of the more disruptive new Web technologies traveling across networks today. To help you minimize future surprises on your network, we've outlined the 10 things you should take to heart about Ajax.
  • Calling WebServices via AJAX
    how do you call web services from JavaScript? At least, that's what they asked me, but not really what they meant (I'll explain what their real question was in a subsequent post).