身份证验证

来源:互联网 发布:访客模式软件 编辑:程序博客网 时间:2024/04/25 15:19
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>


alter function dbo.IDTrue--验证十八位身份证是否正确
(
 @ID varchar(18)
)
returns bit
as
begin
--验证格式是否正确
declare @RESbit
declare @Wtable (rnint,valint)
insertinto  @W(rn,val)
select1,7
unionselect2,9
unionselect3,10
unionselect4,5
unionselect5,8
unionselect6,4
unionselect7,2
unionselect8,1
unionselect9,6
unionselect10,3
unionselect11,7
unionselect12,9
unionselect13,10
unionselect14,5
unionselect15,8
unionselect16,4
unionselect17,2
unionselect18,1
declare @A table(rwnint ,valvarchar(1))
insertinto@A(rwn,val)
select 0,'1'
insertinto@A(rwn,val)
select 1,'0'
insertinto@A(rwn,val)
select 2,'X'
insertinto@A(rwn,val)
select 3,'9'
insertinto@A(rwn,val)
select 4,'8'
insertinto@A(rwn,val)
select 5,'7'
insertinto@A(rwn,val)
select 6,'6'
insertinto@A(rwn,val)
select 7,'5'
insertinto@A(rwn,val)
select 8,'4'
insertinto@A(rwn,val)
select 9,'3'
insertinto@A(rwn,val)
select 10,'2'
declare @iint
declare @jint
declare @S int

iflen(@ID)=18
 begin
 select @S=0,@i=1
 declare @IDIint
 declare @WIint
 declare @PII varchar(1)
 while   @i<=17
    begin
      select @PII=substring(@ID,@i,1)
      if   @PIIlike '[0-9]'
       begin
        select @IDI=convert(int,@PII)
        select @WI=valfrom@Wwhere  rn=@i
        select @j=@IDI*@WI
        select @S=@S+@j
        select @i=@i+1
       end
      else
       begin
             select @RES=0
              return @RES
       end

    end
 select@S=@S%11
 select @IDI=convert(int,substring(@ID,18,1))
 declare @pi  varchar(1)
 select @pi=valfrom @Awhere rwn=@S 
 if  @pi=@IDI
     select @RES=1
 else
     select @RES=0
 end
 else
 begin
    select @RES=0
 end
return @RES
end
go
declare @pc bit
select @pc=dbo.IDTrue('420324198101031224')
select @pc
go

alterfunction   SFZ15To18--十五位升十八
 (
  @sfzvarchar(15)
 )
 returns varchar(18)1<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>