查看: 1023|回复: 3

[问与答] 想对自己网站的输入的文本进行LUHN算法校对

[复制链接]
虎皮猫 发表于 2019-7-27 02:13:33 | 显示全部楼层 |阅读模式
原代码如下,请教下各位大神,数据文本name=account

程序代码
<%
    ' Copyright (c) 2008, reusablecode.blogspot.com; some rights reserved.
    '
    ' This work is licensed under the Creative Commons Attribution License. To view
    ' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or
    ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
    ' 94305, USA.

    ' Luhn (mod 10) algorithm
    function luhn(byVal input)
        dim sum
        dim odd
        dim currentDigit
        dim regEx

        input = CStr(input)
        sum = 0
        odd = CBool(len(input) mod 2)

        ' Remove any non-numeric characters.
        if not isNumeric(input) then
            set regEx = new RegExp
            regEx.Global = true
            regEx.Pattern = "\D"
            input = regEx.Replace(input, "")
            set regEx = nothing
        end if

        ' Calculate sum of digits.
        for i = 1 to len(input)
            currentDigit = cint(mid(input, i, 1))

            if odd then
                sum = sum + currentDigit
            else
                if currentDigit * 2 > 9 then
                    sum = sum + (currentDigit * 2 - 9)
                else
                    sum = sum + (currentDigit * 2)
                end if
            end if

            odd = not odd
        next

        ' Check validity.
        if sum mod 10 = 0 then
            luhn = true
        else
            luhn = false
        end if
    end function

    ' Unit test - expected result is true
    if luhn("9558821402001225732") then
        response.write "true"
    else
        response.write "false"
    end if
%>

ttasp 发表于 2019-7-27 11:38:22 | 显示全部楼层
具体是什么意思?
 楼主| 虎皮猫 发表于 2019-7-28 23:37:31 | 显示全部楼层
ttasp 发表于 2019-7-27 11:38
具体是什么意思?

就是我想把这段代码接到我指定的文本框进行核对校验
xuanxiao 发表于 2019-7-30 09:54:49 | 显示全部楼层
虎皮猫 发表于 2019-7-28 23:37
就是我想把这段代码接到我指定的文本框进行核对校验

ASP+AJAX技术的注册会员程序
http://bbs.ttasp.com/forum.php?m ... =1037&fromuid=1
(出处: 天天ASP家园)

参考下,你这需求是一个问题
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表

在线客服

售前咨询
售后咨询
服务热线
023-58418553
微信公众号