Determine a string contains unicode Character in c#

If you need a function to determine different language such as Chinese/Japanese/French and so on. You may want to use the following function to determine if the input contains Unicode character.

Unicode strings use two bytes per character (or more), ANSI strings only one byte per character. ASCII only extends up to 127. 128..255 is commonly used for ANSI characters. Above that is only Unicode. Some characters from value 128 and above (including 128 itself) map to a unicode character with a value higher than 255 in codepage 1252.

public static bool IsUnicode(string input)
      const int MaxAnsiCode = 255;

      return input.ToCharArray().Any(c => c > MaxAnsiCode);

How to validate Canada Postal Code in C#

Canadian postal code contains both letters and numbers in 6 or 7 characters, such as M3A 1J6, or M3A1J6. Furthermore, not all 26 letters are being used in the letter section of Canadian postal code. See the function below

public static bool IsPostalCode(string postalCode)
      //Canadian Postal Code in the format of "M3A 1A5"
      string pattern = "^[ABCEGHJ-NPRSTVXY]{1}[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}[ ]?[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}[0-9]{1}$";
       Regex reg = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Compiled);
       if (!(reg.IsMatch(postalCode)))
              return false;
       return true;

How to validate username in c# regular expression

We want to set the rules when user choosing their username. In most of cases, a pattern with letter and number is used. We also want to set the length of the username so it does not look ugly. We use the following regular expression to validate a username.

[a-zA-Z] => first character must be a letter
[a-zA-Z0-9] => it can contain letter and number
{5,11} => the length is between 6 to 12

public static bool IsUsername(string username)
      string pattern;
      // start with a letter, allow letter or number, length between 6 to 12.
      pattern = @"^[a-zA-Z][a-zA-Z0-9]{5,11}$";

      Regex regex = new Regex(pattern);
      return regex.IsMatch(username);

How to validate email in .Net c#/

Validation becomes a basic task in any form of application development especially the email validation which is required by any web application that allows user registration.

The following code sample is utilizing the regular expression pattern to validate the email address. If you have any other way of validating emails, please comment below.

C# sample

public static bool IsEmail(string strIn)
      if (string.IsNullOrEmpty(strIn))
           return false;
      return Regex.IsMatch(strIn,
             @"^(?("")("".+?""@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?             @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,6}))$");

VB.Net Sample

Public Shared Function IsEmail(strIn As String) As Boolean
    If String.IsNullOrEmpty(strIn) Then
        Return False
    End If
    Return Regex.IsMatch(strIn, "^(?("")("".+?""@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-zA-Z])@))" & "(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,6}))$")
End Function

Country Drop Down Html Helper for MVC

Almost every website or web application need to display countries in the drop down list. If that’s true to your project, the following country drop down html helper for MVC may save some time for you.

First, we need all the countries information so that we can put into the select list. Thanks to Mads, we can use the XML countries list. or you can download the countries XML List.

Second, A html helper is created for populating the country data into actual HTML format. Simply put the xml file in the App_Data or any folder that works the best for your application.

Continue reading “Country Drop Down Html Helper for MVC”

Ultima VPS Windows Hyper-V Hosting Review

Ultimahost was one of the first hosting companies that offer VPS in Toronto, Canada location in early 2010 in my search vision. At that time, I needed a Windows VPS hosting for my Canadian client’s .Net application, In my research, Ultimahost was one of few that offer unbeatable price, 99.9% up time guarantee and multiple location to choose from including Toronto. On the other hand, multiple mixed review were given as well.

Plan Detail

The sign up process was fluid, Their sales was easy to talk to through the online chatting tool. It’s hard to negotiate with their sales since the price was already one of the lowest online. I was satisfied with the price and plan and took the deal.

Continue reading “Ultima VPS Windows Hyper-V Hosting Review”

Hello world!

Welcome to After you read this, you should delete and write your own post, with a new title above. Or hit Add New on the left (of the admin dashboard) to start a fresh post.

Here are some suggestions for your first post.

  1. You can find new ideas for what to blog about by reading the Daily Post.
  2. Add PressThis to your browser. It creates a new blog post for you about any interesting  page you read on the web.
  3. Make some changes to this page, and then hit preview on the right. You can alway preview any post or edit you before you share it to the world.