<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Kris' Blog &#187; globalization</title>
	<atom:link href="http://krisselden.com/tag/globalization/feed/" rel="self" type="application/rss+xml" />
	<link>http://krisselden.com</link>
	<description>Focused on software development.</description>
	<lastBuildDate>Thu, 27 Mar 2008 03:06:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Validating fullwidth alphanumeric input in .Net</title>
		<link>http://krisselden.com/2007/02/19/validating-fullwidth-alphanumeric-input-in-net/</link>
		<comments>http://krisselden.com/2007/02/19/validating-fullwidth-alphanumeric-input-in-net/#comments</comments>
		<pubDate>Tue, 20 Feb 2007 03:52:09 +0000</pubDate>
		<dc:creator>Kris</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[ffxi]]></category>
		<category><![CDATA[globalization]]></category>

		<guid isPermaLink="false">http://krisselden.com/2007/02/19/validating-fullwidth-alphanumeric-input-in-net/</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>One of the things that attracted me to playing <a href="http://www.playonline.com/ff11us/">Final Fantasy XI</a> (a <a href="http://en.wikipedia.org/wiki/MMORPG">MMORPG</a>) 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.</p>
<p>I noticed that when a Japanese player says 5000 gil (Final Fantasy currency) it looks wide and spaced funny like &#8220;５０００　ｇｉｌ.&#8221; As Japanese players are generally considered to be more <a href="http://en.wikipedia.org/wiki/Leetspeak">l33t</a> by the American players, some even try to mimic this by adding spaces like so &#8220;5 0 0 0  g i l.&#8221; People even <a href="http://www.windower.net/forums/viewtopic.php?t=2050">hack</a> the game to input Japanese text on the American client.</p>
<p>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.<br />
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.</p>
<p>No, int.Parse(string) does not work.</p>
<p>You could loop over each character in the string and use char.IsNumber(char) for validation. You&#8217;d probably want to be more specific char.<a href="http://msdn2.microsoft.com/en-us/library/system.char.getunicodecategory.aspx">GetUnicodeCategory</a>(char) since we don&#8217;t need to support roman numerals.</p>
<pre class="line5"><code>protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
    foreach (char c in args.Value)
        if (char.GetUnicodeCategory(c) != UnicodeCategory.DecimalDigitNumber)
            args.IsValid = false;
}</code></pre>
<p>You probably want to normalize it before saving it into the database. You could use (int)char.<a href="http://msdn2.microsoft.com/en-us/library/system.char.getnumericvalue.aspx">GetNumericValue</a>(char) but even easier is to use string.<a href="http://msdn2.microsoft.com/en-us/library/ebza6ck1.aspx">Normalize</a>(<a href="http://msdn2.microsoft.com/en-us/library/system.text.normalizationform.aspx">NormalizationForm</a>.FormKD). You could even normalize the string before validation and run your existing validation on the normalized string.</p>
<p>Output from the <a href="http://msdn2.microsoft.com/en-us/library/f177hahy(VS.80).aspx">Immediate Window (Ctrl-Alt-I)</a></p>
<pre class="line9"><code>'\xFF15'
65301 '５'
Char.IsNumber('５')
true
Char.GetUnicodeCategory('５')
DecimalDigitNumber
Char.GetNumericValue('５')
5.0
"５０００　ｇｉｌ".Normalize(System.Text.NormalizationForm.FormKD)
"5000 gil"</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://krisselden.com/2007/02/19/validating-fullwidth-alphanumeric-input-in-net/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

