Don't like ads? PRO users don't see any ads ;-)
Guest

Html401IdUtil

By: andrew4582 on Mar 8th, 2011  |  syntax: C#  |  size: 0.96 KB  |  hits: 126  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // Valid IDs are defined in http://www.w3.org/TR/html401/types.html#type-id
  2.         private static class Html401IdUtil {
  3.             private static bool IsAllowableSpecialCharacter(char c) {
  4.                 switch (c) {
  5.                     case '-':
  6.                     case '_':
  7.                     case ':':
  8.                         // note that we're specifically excluding the '.' character
  9.                         return true;
  10.  
  11.                     default:
  12.                         return false;
  13.                 }
  14.             }
  15.  
  16.             private static bool IsDigit(char c) {
  17.                 return ('0' <= c && c <= '9');
  18.             }
  19.  
  20.             public static bool IsLetter(char c) {
  21.                 return (('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z'));
  22.             }
  23.  
  24.             public static bool IsValidIdCharacter(char c) {
  25.                 return (IsLetter(c) || IsDigit(c) || IsAllowableSpecialCharacter(c));
  26.             }
  27.         }