Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 9th, 2012  |  syntax: None  |  size: 1.76 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. CPF Validation in classic asp
  2. function ValidateCPFNew(cpf)
  3.     Dim multiplic1, multiplic2
  4.     multiplic1=Array(10, 9, 8, 7, 6, 5, 4, 3, 2)
  5.     multiplic2=Array(11, 10, 9, 8, 7, 6, 5, 4, 3, 2 )
  6.     Dim tempCpf,digit,sum,remainder,i,RegXP
  7.     cpf = Trim(cpf)
  8.     cpf = Replace(cpf,".", "")
  9.     cpf = Replace(cpf,"-", "")
  10.     if (Len(cpf) <> 11) Then
  11.         ValidateCPFNew = false
  12.     else
  13.         tempCpf = Left (cpf, 9)
  14.         sum = 0
  15.  
  16.         Dim intCounter
  17.         Dim intLen
  18.         Dim arrChars()
  19.  
  20.         intLen = Len(tempCpf)-1
  21.         redim arrChars(intLen)
  22.  
  23.         For intCounter = 0 to intLen
  24.             arrChars(intCounter) = Mid(tempCpf, intCounter + 1,1)
  25.         Next
  26.  
  27.         i=0
  28.         For i = 0 to 8
  29.             sum =sum + CInt(arrChars(i)) * multiplic1(i)
  30.         Next
  31.  
  32.         remainder = sum Mod 11
  33.         If (remainder < 2) Then
  34.             remainder = 0
  35.         else
  36.             remainder = 11 - remainder
  37.         End If
  38.  
  39.         digit = CStr(remainder)
  40.         tempCpf = tempCpf & digit
  41.         sum = 0
  42.  
  43.         intLen = Len(tempCpf)-1
  44.         redim arrChars(intLen)
  45.         intCounter= 0
  46.         For intCounter = 0 to intLen
  47.             arrChars(intCounter) = Mid(tempCpf, intCounter + 1,1)
  48.         Next
  49.         i=0
  50.         For i = 0 to 9
  51.             sum =sum + CInt(arrChars(i)) * multiplic2(i)
  52.         Next        
  53.         remainder = sum Mod 11
  54.  
  55.         If (remainder < 2) Then
  56.             remainder = 0
  57.         else
  58.             remainder = 11 - remainder
  59.         End If      
  60.         digit = digit & CStr(remainder)
  61.  
  62.         Set RegXP=New RegExp
  63.             RegXP.IgnoreCase=1
  64.             RegXP.Pattern=digit & "$"
  65.  
  66.         If RegXP.test(cpf) Then
  67.             ValidateCPFNew = true
  68.         else
  69.             ValidateCPFNew = false
  70.         end if
  71.     end if
  72. end Function