Kris' Blog

RSS feed

Rails deployment

I’ve been meaning to learn capistrano, but I have a tendency to avoid server configuration, setup and deployment related tasks. Until now, I’ve been running my rails app with svn checkout and script/server -d on production.

To my surprise, there was no headache and it was actually pretty straightforward. At least with these helpful links:

While the first link covers everything, I used the other two to setup mongrel cluster and apache.


Validating fullwidth alphanumeric input in .Net

One of the things that attracted me to playing Final Fantasy XI (a MMORPG) was the opportunity to play on the same server with Japanese players. I’ve been a fan of anime since I was a kid and always curious about Japanese culture.

I noticed that when a Japanese player says 5000 gil (Final Fantasy currency) it looks wide and spaced funny like “5000 gil.” As Japanese players are generally considered to be more l33t by the American players, some even try to mimic this by adding spaces like so “5 0 0 0 g i l.” People even hack the game to input Japanese text on the American client.

So when my brother called me in a bind about a missed requirement to accept double byte credit card numbers, I knew exactly what he was talking about.
Luckily the web browser deals with the input and on the ASP.NET side it is decoded into a Unicode string. From there it is actually quite simple.

No, int.Parse(string) does not work.

You could loop over each character in the string and use char.IsNumber(char) for validation. You’d probably want to be more specific char.GetUnicodeCategory(char) since we don’t need to support roman numerals.

protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
    foreach (char c in args.Value)
        if (char.GetUnicodeCategory(c) != UnicodeCategory.DecimalDigitNumber)
            args.IsValid = false;
}

You probably want to normalize it before saving it into the database. You could use (int)char.GetNumericValue(char) but even easier is to use string.Normalize(NormalizationForm.FormKD). You could even normalize the string before validation and run your existing validation on the normalized string.

Output from the Immediate Window (Ctrl-Alt-I)

'\xFF15'
65301 '5'
Char.IsNumber('5')
true
Char.GetUnicodeCategory('5')
DecimalDigitNumber
Char.GetNumericValue('5')
5.0
"5000 gil".Normalize(System.Text.NormalizationForm.FormKD)
"5000 gil"