加载中...
推荐位 推荐位

检查专利号(专利申请号)有效性的delphi函数

发布时间:2011.11.22 湖南省查看:5004 评论:3

function IsValidSQH(insqh:string):boolean;

var

 sqh,tail,param:string;

 i,sqyear,sum:integer;

begin

 Result:=true;

 sqh:=lowercase(trim(insqh));

 if not ((length(sqh)=10) or (length(sqh)=14)) then Result:=false;

 if length(sqh)=10 then//8位申请号,85年~03年

   begin

     for i:=0 to 7 do//前8为必须为数字

       if not (sqh[i+1] in ['0'..'9']) then Result:=false;



     if not (sqh[3] in ['1'..'3','8','9']) then Result:=false;//第三位类型必须为1、2、3、8、9



     if sqh[1]='0' then sqyear:=strtoint('20'+copy(sqh,1,2)) else sqyear:=strtoint('19'+copy(sqh,1,2));

     if ((sqyear<1984) or (sqyear>2003)) then Result:=false;//年份必须是1984~2003之间



     if not (sqh[9]='.') then Result:=false;//第9位必须为小数点



     if not (sqh[10] in ['0'..'9','x']) then Result:=false;//验证码必须为数字或者x

     param:='23456789';

     sum:=0;

     for i:= 0 to 7 do

       sum:=sum+strtoint(param[i+1])*strtoint(sqh[i+1]);

     sum:=sum mod 11;

     if sum=10 then tail:='x' else tail:=inttostr(sum);

     if not (sqh[10]=tail) then Result:=false;//第10位必须与通过前8位计算的验证码保持一致。

   end;

 if length(sqh)=14 then//12位申请号,03年+

   begin

     for i:=0 to 11 do//前8为必须为数字

       if not (sqh[i+1] in ['0'..'9']) then Result:=false;



     if not (sqh[5] in ['1'..'3','8','9']) then Result:=false;//第三位类型必须为1、2、3、8、9



     sqyear:=strtoint(copy(sqh,1,4));

     if ((sqyear<2003) or (sqyear>strtoint(FormatDateTime('yyyy',Now)))) then Result:=false;//年份必须是2003后



     if not (sqh[13]='.') then Result:=false;//第13位必须为小数点



     if not (sqh[14] in ['0'..'9','x']) then Result:=false;

     param:='234567892345';

     sum:=0;

     for i:= 0 to 11 do

       sum:=sum+strtoint(param[i+1])*strtoint(sqh[i+1]);

     sum:=sum mod 11;

     if sum=10 then tail:='x' else tail:=inttostr(sum);

     if not (sqh[14]=tail) then Result:=false;//第14位必须与通过前12位计算的验证码保持一致。

   end;

end;


标签: 专利申请 专利号 检查


分享

收藏(1)

点赞

举报

评论列表

  • 第1楼
    能编写一个专利公开号转申请号的嘛,最近很头疼这个事

    2011/11/22 16:52 [来自北京市]

    0 举报
  • 第2楼
    这个要赞!

    2011/11/22 18:33 [来自北京市]

    0 举报
  • 第3楼
    不错,值得学习。

    2011/11/23 09:40 [来自陕西省]

    0 举报

快速回复