我的證照


國際專案管理師

My Profile


學歷:中華大學機械系
現職:媒體產業資訊單位副主任
專長:系統設計架構

最新回應

檢查統一編號是不是正確

 

01 /// <summary>
02         /// 檢查統一編號是否正確
03         /// </summary>
04         /// <param name="id1">要檢查的統一編號字串</param>
05         /// <returns>Boolean值</returns>

06         public static Boolean isCompanyID(String strIdno)
07         {
08             if (strIdno == null || strIdno.Trim().Length != 8)
09             {
10                 return false;
11             }

12             else if (!isInteger(strIdno))
13             {
14                 return false;
15             }

16
17             int ii;
18
19             try
20             {
21                 ii = Convert.ToInt32(strIdno);
22             }

23             catch (Exception)
24             {
25                 return false;
26             }

27             int c1;
28             int c2;
29             int c3;
30             int c4;
31             int c5;
32             int c6;
33             int c7;
34             int c8;
35             try
36             {
37                 c1 = Convert.ToInt32(strIdno.Substring(0, 1));
38                 c2 = Convert.ToInt32(strIdno.Substring(1, 1));
39                 c3 = Convert.ToInt32(strIdno.Substring(2, 1));
40                 c4 = Convert.ToInt32(strIdno.Substring(3, 1));
41                 c5 = Convert.ToInt32(strIdno.Substring(4, 1));
42                 c6 = Convert.ToInt32(strIdno.Substring(5, 1));
43                 c7 = Convert.ToInt32(strIdno.Substring(6, 1));
44                 c8 = Convert.ToInt32(strIdno.Substring(7, 1));
45             }

46             catch (Exception)
47             {
48                 return false;
49             }

50
51             int y = c1 + c3 + c5 + c8;
52             int t = c2 * 2;
53             y = y + t / 10 + t % 10;
54             t = c4 * 2;
55             y = y + t / 10 + t % 10;
56             t = c6 * 2;
57             y = y + t / 10 + t % 10;
58             t = c7 * 4;
59             y = y + t / 10 + t % 10;
60             int k = y;
61             if (y % 10 == 0)
62             {
63                 return true;
64             }

65             if (c7 == 7)
66             {
67                 y -= 9;
68                 return y % 10 == 0;
69             }

70             else
71             {
72                 return false;
73             }

74         }

2008/10/14 20:37 | 閱讀數 : 5806 1 人收藏 我要推薦 | 4 Comments | 文章分類 : C# 訂閱


關連文章

回應

  • 找檢查統編過路人 2008/10/20 下午 06:34 回覆

    # re: 檢查統一編號是不是正確

    這有一篇可以參考看看,程式碼比較精簡
    http://jian-zhoung.blogspot.com/2008/10/c.html
  • brucecho 2008/10/20 下午 09:17 回覆

    # re: 檢查統一編號是不是正確

    感謝您的指教,我會試試看

  • Jay 2008/11/7 下午 03:51 回覆

    # re: 檢查統一編號是不是正確

    ^^~您好 小弟有參考您的文章

    http://herolin.mine.nu/entry/is-valid-TW-company-ID 特來告知一下 謝謝
  • hatelove 2009/2/13 下午 06:26 回覆

    # re: 檢查統一編號是不是正確

    Dear 小卓,

    我之前的文章有寫好的JavaScript function,

    如果您也有client端驗證的需求,可以供您參考。

    http://www.dotblogs.com.tw/hatelove/archive/2009/01/07/6683.aspx

     

標題 *
名稱 *
Email (將不會被顯示)
Url
回應
登入後使用進階評論
Please add 6 and 2 and type the answer here: