【问题标题】:CPF Validation in classic asp经典asp中的CPF验证
【发布时间】:2012-07-28 08:44:56
【问题描述】:

我是经典 asp 的新手。我想要经典 asp 中的 CPF 验证功能。

以下链接在 javascript 和 vb.net 中具有 CPF 验证功能,但我希望在经典 asp /vbscript 中使用它

http://codigofonte.uol.com.br/codigo/js-dhtml/validacao/validar-cpf-via-javascript

http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=3811&lngWId=10

谢谢

【问题讨论】:

  • 到目前为止你做了什么工作?您遇到了哪些具体问题? SO 不是人们为您编写代码的地方。

标签: asp-classic vbscript


【解决方案1】:

最后,我自己编写了一个 vbscript 函数。将来可能会对某人有所帮助。

function ValidateCPFNew(cpf)
    Dim multiplic1, multiplic2
    multiplic1=Array(10, 9, 8, 7, 6, 5, 4, 3, 2)
    multiplic2=Array(11, 10, 9, 8, 7, 6, 5, 4, 3, 2 )
    Dim tempCpf,digit,sum,remainder,i,RegXP
    cpf = Trim(cpf)
    cpf = Replace(cpf,".", "")
    cpf = Replace(cpf,"-", "")
    if (Len(cpf) <> 11) Then
        ValidateCPFNew = false
    else
        tempCpf = Left (cpf, 9)
        sum = 0

        Dim intCounter
        Dim intLen 
        Dim arrChars()

        intLen = Len(tempCpf)-1
        redim arrChars(intLen)

        For intCounter = 0 to intLen
            arrChars(intCounter) = Mid(tempCpf, intCounter + 1,1)
        Next

        i=0
        For i = 0 to 8
            sum =sum + CInt(arrChars(i)) * multiplic1(i)
        Next

        remainder = sum Mod 11
        If (remainder < 2) Then
            remainder = 0
        else
            remainder = 11 - remainder
        End If

        digit = CStr(remainder)
        tempCpf = tempCpf & digit
        sum = 0

        intLen = Len(tempCpf)-1
        redim arrChars(intLen)
        intCounter= 0
        For intCounter = 0 to intLen
            arrChars(intCounter) = Mid(tempCpf, intCounter + 1,1)
        Next
        i=0
        For i = 0 to 9
            sum =sum + CInt(arrChars(i)) * multiplic2(i)
        Next        
        remainder = sum Mod 11

        If (remainder < 2) Then
            remainder = 0
        else
            remainder = 11 - remainder
        End If      
        digit = digit & CStr(remainder)

        Set RegXP=New RegExp
            RegXP.IgnoreCase=1
            RegXP.Pattern=digit & "$"

        If RegXP.test(cpf) Then 
            ValidateCPFNew = true
        else
            ValidateCPFNew = false
        end if
    end if
end Function

【讨论】:

    猜你喜欢
    • 2011-09-12
    • 2010-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-22
    • 1970-01-01
    • 2011-03-01
    • 1970-01-01
    相关资源
    最近更新 更多