20100831 学习记录:asp校验信用卡号

本文介绍了一种使用ASP来判断字符串是否为数字的方法,并提供了一个检查信用卡号是否有效的函数。通过具体代码示例展示了如何逐字符验证字符串以及如何根据特定算法验证信用卡号码。

ASP

 

 判断一个字符串是否是数字

    for i=1 to Len(cNumber)
      
if not IsNumeric(Mid(cNumber,i,1)) then
          isNum 
= false
          response.write(
"i:" & i & "--" & Mid(cNumber,i,1& "<br>")
      
end if
      
      
if not isNum  then  exit for '跳出for循环
    next 


 判断信用卡号是否有效

    function isCreditCard(cardNo) 
 
        isCreditCard 
= false 
        lCard 
= len(cardNo) 
        lC 
= right(cardNo, 1
        cStat 
= 0 
        
for i = (lCard - 1to 1 step -1 
            tempChar 
= mid(cardNo, i, 1
            d 
= cint(tempChar) 
            
if lcard mod 2 = 1 then 
                temp 
= d * (1 + ((i+1mod 2)) 
            
else 
                temp 
= d * (1 + (i mod 2)) 
            
end if 
            
if temp < 10 then 
                cStat 
= cStat + temp  
            
else 
                cStat 
= cStat + temp - 9 
            
end if 
        
next 
        cStat 
= (10 - (cStat mod 10)) mod 10 
        
if cint(lC) = cStat then isCreditCard = true 
    
end function 


 

 

转载于:https://www.cnblogs.com/neru/archive/2010/08/31/1813929.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值