Friday, June 08, 2007

Notebarn: Launching URLs and International Phone Numbers (Includes Crash Couse in Numeric Regular Expressions)

A lot of visitors to this blog and the Notebarn project page (where you can download the app) are from outside North America, and all of those folks got a raw deal from my last update.

I added the ability to dial numbers from a note, but the phone number recognition was based on a hard-coded pattern that looks like a North American phone number (basically, 10 digits with some optional delimiters).

So I've got an update that moves the phone number recognition out to a configuration file, where you can put in a localized phone number pattern.

I also found it really frustrating to put a URL in a note and then have to key it in later to browse. So this update recognizes URLs in notes and lets you launch them just like dialing a phone number from a note.

URLs / web browsing works straight out of the box. For localized phone numbers there's, um, a small catch.

The Catch

I did not set up a list of international phone number patterns. So, in this release, if you're outside North America, you'll need to add your own phone number pattern to the config file. Here's how it works:

  1. Install the new Notebarn with the latest OTA installer. The install will place a config file called notebarn.config.txt in the Program Files/Notebarn directory on your device, right alongside the executable.
  2. If you have a regular text editor on your device you can edit the file in place and skip to step 3. Otherwise, use ActiveSync to grab the file, pull it over to your PC, and edit it there (with an editor like Notepad). When you're done you can push it back to the device with the changes.
  3. In the config file you will see two lines like this:

    #Add a RegEx for your localized phone number format here:

    PHONE=\d{3}\D{0,2}\d{3}\D?\d{4}\D

The beast on the right is called a regular expression, and your .net-enabled Smartphone has a great engine for processing them. Microsoft has docs on the format. But you don't need to read all that. The cheatsheet for phone number patterns works like this: \d means a digit. \d{3} means exactly 3 digits in a row. \D means a non-digit. Specifying non-digits is how you look for delimiters used between groups of numbers, like a period, space, dash, parens, etc. And \D{0,2} means anywhere from 0 to 2 non-digits in a row. The \D? is shorthand for \D{0,1}, or "zero or one non-digit."

So all together, the North American pattern above means 3 digits (the "area code") followed by 0, 1, or 2 non digits (think of 415-555-1212 or (415) 555-1212), then 3 digits, optionally a nondigit, 4 more digits, and a non-digit to mark the end. How does the phone dial if we've recognized an extra non-digit at the end? Well, the phone app in Windows Mobile is smart enough to drop the non-digit parts of the phone number when it dials.

If you put together an expression for your locale (or borrow one from another program), feel free to email me or post it in the comments. In the next release I'll include all of them in the config file to make it easier to set up.

No comments: