Ir para conteúdo
Fórum Script Brasil
  • 0

validação de cpf barrar inserção de usuário


Guest franciscobiscaino

Pergunta

Guest franciscobiscaino

como faço p/ o script validação de cpf barrar inserção de usuário

o script é o seguinte

na pg de post é o seguinte

dizendo que o cpf é requerido

If Len(Trim(sCPF)) = 0 AND gbReqCPF Then

sString = sString & ErrorString(GLS_CPF)

End If

Function ErrorString(sField)

ErrorString = replace(GLS_FieldErr,"%FIELDNAME%","<B>" & UCASE(sField) & "</B>") & "<BR>"

End Function

agora na pg que contentem todas as funções é o código de validação

function CalculaCPF()

Dim RecebeCPF, Numero(11), soma, resultado1, resultado2

RecebeCPF = Request("CPF")

'Retirar todos os caracteres que não sejam 0-9

s=""

for x=1 to len(RecebeCPF)

ch=mid(RecebeCPF,x,1)

if asc(ch)>=48 and asc(ch)<=57 then

s=s & ch

end if

next

RecebeCPF = s

if len(RecebeCPF) <> 11 then

response.write("<h1>&Eacute; obrigat&oacute;rio o CPF com 11 d&iacute;gitos</h1>")

elseif RecebeCPF = "00000000000" then

response.write("<h1>CPF Inválido</h1>")

else

Numero(1) = Cint(Mid(RecebeCPF,1,1))

Numero(2) = Cint(Mid(RecebeCPF,2,1))

Numero(3) = Cint(Mid(RecebeCPF,3,1))

Numero(4) = Cint(Mid(RecebeCPF,4,1))

Numero(5) = Cint(Mid(RecebeCPF,5,1))

Numero(6) = CInt(Mid(RecebeCPF,6,1))

Numero(7) = Cint(Mid(RecebeCPF,7,1))

Numero(8) = Cint(Mid(RecebeCPF,8,1))

Numero(9) = Cint(Mid(RecebeCPF,9,1))

Numero(10) = Cint(Mid(RecebeCPF,10,1))

Numero(11) = Cint(Mid(RecebeCPF,11,1))

soma = 10 * Numero(1) + 9 * Numero(2) + 8 * Numero(3) + 7 * Numero(4) + 6 * Numero(5) + 5 * Numero(6) + 4 * Numero(7) + 3 * Numero(8) + 2 * Numero(9)

soma = soma -(11 * (int(soma / 11)))

if soma = 0 or soma = 1 then

resultado1 = 0

else

resultado1 = 11 - soma

end if

if resultado1 = Numero(10) then

soma = Numero(1) * 11 + Numero(2) * 10 + Numero(3) * 9 + Numero(4) * 8 + Numero(5) * 7 + Numero(6) * 6 + Numero(7) * 5 + Numero(8) * 4 + Numero(9) * 3 + Numero(10) * 2

soma = soma -(11 * (int(soma / 11)))

if soma = 0 or soma = 1 then

resultado2 = 0

else

resultado2 = 11 - soma

end if

if resultado2 = Numero(11) then

response.write("<h1>CPF Válido</h1>")

else

response.write("<h1>CPF Inválido</h1>")

end if

else

response.write("<h1>CPF Inválido</h1>")

end if

end if

end function

como eu faço p/ que o usuário com cpf inválido não seja inscrito no site

a e detalhe a parte de inseção é a seguinte

sUserName = "" & RequestValue("username")

sName = "" & RequestValue("name")

sEmail = "" & RequestValue("email")

sDianasc = "" & RequestValue("Dianasc")

sMesnasc = "" & RequestValue("Mesnasc")

sAnonasc = "" & RequestValue ("Anonasc")

sSexo = "" & RequestValue("Sexo")

sAddressOne = "" & RequestValue("addressone")

sBairro1 = "" & RequestValue("Bairro1")

sAddressTwo = "" & RequestValue("addresstwo")

sBairro2 = "" & RequestValue("Bairro2")

sFone = "" & RequestValue("fone")

sDdd1 = "" & RequestValue("ddd1")

sCel = "" & RequestValue ("cel")

sDdd2 = "" & RequestValue("ddd2")

sCPF = "" & RequestValue("CPF")

sCity = "" & RequestValue("city")

sState = "" & RequestValue("state")

sZip = "" & RequestValue("zip")

sCountry = "" & RequestValue("country")

sInfoad = "" & RequestValue("Infoad")

sNovidades = "" & RequestValue("Novidades")

sString = ""

npSQL = "INSERT INTO tblQARegistration (regUserName, regPassword, regValidated, regName, anonasc, mesnasc, dianasc, regEmail, " & _

"regSexo, regBairro1, regBairro2, regAddress1, regAddress2,regFone,regDdd1, regCel, regDdd2, regCPF, regCity, regState, regZip, Infoad, Novidades, regCountry) VALUES (" & _

SQLStr(sUserName) & ", " & _

SQLStr(sPassword) & " , " & _

SQLBool(gbUsersAdd) & ", " & _

SQLStr(sName) & ", " & _

SQLStr(sAnonasc) & ", " & _

SQLStr(sMesnasc) & ", " & _

SQLStr(sDianasc) & ", " & _

SQLStr(sEmail) & ", " & _

SQLStr(sSexo) & ", " & _

SQLStr(sAddressOne) & ", " & _

SQLStr(sBairro1) & ", " & _

SQLStr(sAddressTwo) & ", " & _

SQLStr(sBairro2) & ", " & _

SQLStr(sfone) & ", " & _

SQLStr(sDdd1) & ", " & _

SQLStr(sCel) & ", " & _

SQLStr(sDdd2) & ", " & _

SQLStr(sCPF) & ", " & _

SQLStr(sCity) & ", " & _

SQLStr(sState) & ", " & _

SQLStr(sZip) & "," & _

SQLStr(sInfoad) & "," & _

SQLStr(sNovidades) & "," & _

SQLStr(sCountry) & " )"

gobjConnect.Execute(npSQL)

Link para o comentário
Compartilhar em outros sites

Posts Recomendados

  • 0
Guest francisco biscaino

O USUÁRIO ELE É ACEITO NO CADASTRO MESMO COM O CPF INVÁLIDO

EU QUERO QUE ISTO NÃO ACONTEÇA SE você QUIZER VER COMO ELE ESTA FUNCIONANDO WWW.MECALIVRE.COM.BR

Link para o comentário
Compartilhar em outros sites

  • 0

Acho que agora entendi, tu quer verificar se o cpf existe?

Se for isso, é relativamente simples de fazer.

Não tenho algoritmo pra isso, mas vou explicar como funciona a verificação...

Tu pega o número do cpf dígito a dígito, soma eles, se o resultado tiver os dígitos iguais, é válido, senão, é inválido.

Ex.: 43915515000

somando 4 + 3 + 9 + 1 + 5 + 5 + 1 + 5 + 0 + 0 + 0

obtem-se 33, portanto é um cpf válido.

Já se o último dígito do cpf anterior fosse alterado para 1, teríamos 34 como resultado da soma, portanto um número inválido.

Não sei se era bem isso que tu queria, mas espero ter ajudado.

:)

Link para o comentário
Compartilhar em outros sites

  • 0
há só mais um detalhe tb quero que usuários com o mesmo cfp não sejam incluidos

Para isso o teste é simples, tu pode colocar teu campo cpf no banco de dados como único, e também no momento da inclusão, pode percorrer o banco de dados e procurar o cpf, se ele existir tu devolve um erro...

abre um recordset com uma consulta SQL mais ou menos assim:

  SELECT cpf FROM cadastro WHERE cpf = [Campo CPF do FORM]
Depois tu testa:
   if rst.nomatch then
           'inclui pois ainda não existe
    else
           'retorna o erro
    end if

Espero ter ajudado...

Link para o comentário
Compartilhar em outros sites

  • 0

vou tentar a parte que você me disse vobre verificar o usuário com o mesmo cpf

mas o sistema de registro de usuários ele já tem o o sistema de verficar se o cpf é valido ele esta ai em cima quando eu cito sobre ele o que eu quero mesmo é que ele alem de verificar se o usuário tem o cpf inválido(isto ele já faz) ele barre o usuário com cpf inválido de ser inscrito no site

Link para o comentário
Compartilhar em outros sites

  • 0

if resultado2 = Numero(11) then
    response.write("<h1>CPF Válido</h1>") 
else
    response.write("<h1>CPF Inválido</h1>")
end if

No lugar de CPF inválido, tu simplesmente retorna um valor e não inclui ele no banco...

Link para o comentário
Compartilhar em outros sites

  • 0

É simples, onde é inválido tu não faz nada, só manda ele escrever que á inválido, já no válido, tu coloca a query de inserção dos dados no banco...

Link para o comentário
Compartilhar em outros sites

  • 0

if resultado2 = Numero(11) then
    npSQL = "INSERT INTO tblQARegistration (regUserName, regPassword, regValidated, regName, anonasc, mesnasc, dianasc, regEmail, " & _
"regSexo, regBairro1, regBairro2, regAddress1, regAddress2,regFone,regDdd1, regCel, regDdd2, regCPF, regCity, regState, regZip, Infoad, Novidades, regCountry) VALUES (" & _
SQLStr(sUserName) & ", " & _
SQLStr(sPassword) & " , " & _
SQLBool(gbUsersAdd) & ", " & _
SQLStr(sName) & ", " & _
SQLStr(sAnonasc) & ", " & _
SQLStr(sMesnasc) & ", " & _
SQLStr(sDianasc) & ", " & _
SQLStr(sEmail) & ", " & _
SQLStr(sSexo) & ", " & _
SQLStr(sAddressOne) & ", " & _
SQLStr(sBairro1) & ", " & _
SQLStr(sAddressTwo) & ", " & _
SQLStr(sBairro2) & ", " & _
SQLStr(sfone) & ", " & _
SQLStr(sDdd1) & ", " & _
SQLStr(sCel) & ", " & _
SQLStr(sDdd2) & ", " & _
SQLStr(sCPF) & ", " & _
SQLStr(sCity) & ", " & _
SQLStr(sState) & ", " & _
SQLStr(sZip) & "," & _
SQLStr(sInfoad) & "," & _
SQLStr(sNovidades) & "," & _
SQLStr(sCountry) & " )"
gobjConnect.Execute(npSQL)
response.write("<h1>Cadastro enviado com sucesso!</h1>") 
else
   response.write("<h1>CPF Inválido</h1>")
end if

É mais ou menos essa a logica...

Link para o comentário
Compartilhar em outros sites

  • 0

Tudo bem, e se não funcionar posta aqui o erro que a gente tenta te ajudar

:)

Link para o comentário
Compartilhar em outros sites

  • 0

TO TENTANDO AQUI MAS NÃO TA DANDO CERTO VEJA COMO FICOU O CÓDIGO

<!-- #include file="CONFIGS.asp" -->

<%

'***********************************************************

* *

'***********************************************************

sUserName = "" & RequestValue("username")

sName = "" & RequestValue("name")

sEmail = "" & RequestValue("email")

sDianasc = "" & RequestValue("Dianasc")

sMesnasc = "" & RequestValue("Mesnasc")

sAnonasc = "" & RequestValue ("Anonasc")

sSexo = "" & RequestValue("Sexo")

sAddressOne = "" & RequestValue("addressone")

sBairro1 = "" & RequestValue("Bairro1")

sAddressTwo = "" & RequestValue("addresstwo")

sBairro2 = "" & RequestValue("Bairro2")

sFone = "" & RequestValue("fone")

sDdd1 = "" & RequestValue("ddd1")

sCel = "" & RequestValue ("cel")

sDdd2 = "" & RequestValue("ddd2")

sCPF = "" & RequestValue("CPF")

sCity = "" & RequestValue("city")

sState = "" & RequestValue("state")

sZip = "" & RequestValue("zip")

sCountry = "" & RequestValue("country")

sInfoad = "" & RequestValue("Infoad")

sNovidades = "" & RequestValue("Novidades")

sString = ""

OpenDBConn

DoPageHeader

If Len(Trim(sUserName)) = 0 Then

sString = sString & ErrorString(GLS_UserNameDet)

End If

If Len(Trim(sName)) = 0 Then

sString = sString & ErrorString(GLS_Name)

End If

If Len(Trim(sEmail)) = 0 Then

sString = sString & ErrorString(GLS_Email)

End If

If Len(Trim(sAddressOne)) = 0 AND gbReqAddress Then

sString = sString & ErrorString(GLS_AddressOne)

End If

If Len(Trim(sCPF)) = 0 AND gbReqCPF Then

sString = sString & ErrorString(GLS_CPF)

End If

If Len(Trim(sCity)) = 0 AND gbReqCity Then

sString = sString & ErrorString(GLS_City)

End If

If Len(Trim(sState)) = 0 AND gbReqState Then

sString = sString & ErrorString(GLS_State)

End If

If Len(Trim(sZip)) = 0 AND gbReqZip Then

sString = sString & ErrorString(GLS_Zip)

End If

If Len(Trim(sCountry)) = 0 AND gbReqCountry Then

sString = sString & ErrorString(GLS_Country)

End If

If sString <> "" Then

Response.Write "<CENTER>" & gsErrorTextOpen & sString & "<BR>" & GLS_GoBack & gsErrorTextClose & "</CENTER>"

Else

CheckName

End If

DoPageFooter

Function ErrorString(sField)

ErrorString = replace(GLS_FieldErr,"%FIELDNAME%","<B>" & UCASE(sField) & "</B>") & "<BR>"

End Function

Sub CheckName

sSQL = sSQL & "SELECT COUNT(*) as Total FROM tblQARegistration WHERE regUserName = " & SQLStr(sUserName)

Set CountRS = gobjConnect.Execute(sSQL)

If CountRS.Fields("Total") > 0 Then

Response.Write "<P ALIGN=""CENTER"">" & gsAuctionTextOpen & replace(GLS_NameTaken, "%NAME%", sUserName) & "<BR>"

Response.Write GLS_TryAgain & gsAuctionTextClose & "</P>"

Else

Call InsertUser

End If

CountRS.Close

set CountRS = Nothing

End Sub

Sub InsertUser

Randomize

sPassword = clng(rnd * 1000000) + 1000

function CalculaCPF()

Dim RecebeCPF, Numero(11), soma, resultado1, resultado2

RecebeCPF = Request("CPF")

'Retirar todos os caracteres que não sejam 0-9

s=""

for x=1 to len(RecebeCPF)

ch=mid(RecebeCPF,x,1)

if asc(ch)>=48 and asc(ch)<=57 then

s=s & ch

end if

next

RecebeCPF = s

if len(RecebeCPF) <> 11 then

response.write("<h1>&Eacute; obrigat&oacute;rio o CPF com 11 d&iacute;gitos</h1>")

elseif RecebeCPF = "00000000000" then

response.write("<h1>CPF Inválido</h1>")

else

Numero(1) = Cint(Mid(RecebeCPF,1,1))

Numero(2) = Cint(Mid(RecebeCPF,2,1))

Numero(3) = Cint(Mid(RecebeCPF,3,1))

Numero(4) = Cint(Mid(RecebeCPF,4,1))

Numero(5) = Cint(Mid(RecebeCPF,5,1))

Numero(6) = CInt(Mid(RecebeCPF,6,1))

Numero(7) = Cint(Mid(RecebeCPF,7,1))

Numero(8) = Cint(Mid(RecebeCPF,8,1))

Numero(9) = Cint(Mid(RecebeCPF,9,1))

Numero(10) = Cint(Mid(RecebeCPF,10,1))

Numero(11) = Cint(Mid(RecebeCPF,11,1))

soma = 10 * Numero(1) + 9 * Numero(2) + 8 * Numero(3) + 7 * Numero(4) + 6 * Numero(5) + 5 * Numero(6) + 4 * Numero(7) + 3 * Numero(8) + 2 * Numero(9)

soma = soma -(11 * (int(soma / 11)))

if soma = 0 or soma = 1 then

resultado1 = 0

else

resultado1 = 11 - soma

end if

if resultado1 = Numero(10) then

soma = Numero(1) * 11 + Numero(2) * 10 + Numero(3) * 9 + Numero(4) * 8 + Numero(5) * 7 + Numero(6) * 6 + Numero(7) * 5 + Numero(8) * 4 + Numero(9) * 3 + Numero(10) * 2

soma = soma -(11 * (int(soma / 11)))

if soma = 0 or soma = 1 then

resultado2 = 0

else

resultado2 = 11 - soma

end if

npSQL = "INSERT INTO tblQARegistration (regUserName, regPassword, regValidated, regName, anonasc, mesnasc, dianasc, regEmail, " & _

"regSexo, regBairro1, regBairro2, regAddress1, regAddress2,regFone,regDdd1, regCel, regDdd2, regCPF, regCity, regState, regZip, Infoad, Novidades, regCountry) VALUES (" & _

SQLStr(sUserName) & ", " & _

SQLStr(sPassword) & " , " & _

SQLBool(gbUsersAdd) & ", " & _

SQLStr(sName) & ", " & _

SQLStr(sAnonasc) & ", " & _

SQLStr(sMesnasc) & ", " & _

SQLStr(sDianasc) & ", " & _

SQLStr(sEmail) & ", " & _

SQLStr(sSexo) & ", " & _

SQLStr(sAddressOne) & ", " & _

SQLStr(sBairro1) & ", " & _

SQLStr(sAddressTwo) & ", " & _

SQLStr(sBairro2) & ", " & _

SQLStr(sfone) & ", " & _

SQLStr(sDdd1) & ", " & _

SQLStr(sCel) & ", " & _

SQLStr(sDdd2) & ", " & _

SQLStr(sCPF) & ", " & _

SQLStr(sCity) & ", " & _

SQLStr(sState) & ", " & _

SQLStr(sZip) & "," & _

SQLStr(sInfoad) & "," & _

SQLStr(sNovidades) & "," & _

SQLStr(sCountry) & " )"

gobjConnect.Execute(npSQL)

Response.Write "<P ALIGN=""CENTER"">" & gsAuctionTextOpen & GLS_RegistrationSuccessMsg & "<BR>"

SendPassEmail(sPassword)

Response.Write GLS_PasswordEmailed & "<BR>"

Response.Write GLS_ChangePasswordInstruction & "<BR>"

Response.Write GLS_ClickToContinue & gsAuctionTextClose & "</P>"

End Sub

Sub SendPassEmail(sPass)

sBody = "" & ReadFile(Server.MapPath("QAEmailTemplates\QANewUserRegister.txt"))

sBody = Replace(sBody, "%USERNAME%", sUserName)

sBody = Replace(sBody, "%PASS%", sPass)

sBody = Replace(sBody, "%AUCPATH%", gsAucURL)

sBody = sBody & Chr(13) & Chr(10) & "Bekan© todos os direitos reservados"

sSubject = GetFirstLine(sBody)

SendEmailMessage sEmail, gsAdminEmail, sSubject, sBody

End Sub

%>

O ERRRO É ESTE

Tipo de erro:

Erro de compilação do Microsoft VBScript (0x800A03EA)

Erro de sintaxe

/QuickAuction200/QuickAuction/QuickAuction/QAPostUser.asp, line 101

function CalculaCPF()

Link para o comentário
Compartilhar em outros sites

  • 0

cara eu vi e alterei para esta forma e não foi tb passou batido do mesmo jeito

<!-- #include file="config.asp" -->

<%

'***********************************************************

'* Desenvolvido por Francisco Biscaino Fone (15) 97069875 *

'* Todos os direitos Reservados *

'***********************************************************

sUserName = "" & RequestValue("username")

sName = "" & RequestValue("name")

sEmail = "" & RequestValue("email")

sDianasc = "" & RequestValue("Dianasc")

sMesnasc = "" & RequestValue("Mesnasc")

sAnonasc = "" & RequestValue ("Anonasc")

sSexo = "" & RequestValue("Sexo")

sAddressOne = "" & RequestValue("addressone")

sBairro1 = "" & RequestValue("Bairro1")

sAddressTwo = "" & RequestValue("addresstwo")

sBairro2 = "" & RequestValue("Bairro2")

sFone = "" & RequestValue("fone")

sDdd1 = "" & RequestValue("ddd1")

sCel = "" & RequestValue ("cel")

sDdd2 = "" & RequestValue("ddd2")

sCPF = "" & RequestValue("CPF")

sCity = "" & RequestValue("city")

sState = "" & RequestValue("state")

sZip = "" & RequestValue("zip")

sCountry = "" & RequestValue("country")

sInfoad = "" & RequestValue("Infoad")

sNovidades = "" & RequestValue("Novidades")

sString = ""

OpenDBConn

DoPageHeader

If Len(Trim(sUserName)) = 0 Then

sString = sString & ErrorString(GLS_UserNameDet)

End If

If Len(Trim(sName)) = 0 Then

sString = sString & ErrorString(GLS_Name)

End If

If Len(Trim(sEmail)) = 0 Then

sString = sString & ErrorString(GLS_Email)

End If

If Len(Trim(sAddressOne)) = 0 AND gbReqAddress Then

sString = sString & ErrorString(GLS_AddressOne)

End If

If Len(Trim(sCPF)) = 0 AND gbReqCPF Then

sString = sString & ErrorString(GLS_CPF)

End If

If Len(Trim(sCity)) = 0 AND gbReqCity Then

sString = sString & ErrorString(GLS_City)

End If

If Len(Trim(sState)) = 0 AND gbReqState Then

sString = sString & ErrorString(GLS_State)

End If

If Len(Trim(sZip)) = 0 AND gbReqZip Then

sString = sString & ErrorString(GLS_Zip)

End If

If Len(Trim(sCountry)) = 0 AND gbReqCountry Then

sString = sString & ErrorString(GLS_Country)

End If

If sString <> "" Then

Response.Write "<CENTER>" & gsErrorTextOpen & sString & "<BR>" & GLS_GoBack & gsErrorTextClose & "</CENTER>"

Else

CheckName

End If

DoPageFooter

Function ErrorString(sField)

ErrorString = replace(GLS_FieldErr,"%FIELDNAME%","<B>" & UCASE(sField) & "</B>") & "<BR>"

End Function

Sub CheckName

sSQL = sSQL & "SELECT COUNT(*) as Total FROM tblQARegistration WHERE regUserName = " & SQLStr(sUserName)

Set CountRS = gobjConnect.Execute(sSQL)

If CountRS.Fields("Total") > 0 Then

Response.Write "<P ALIGN=""CENTER"">" & gsAuctionTextOpen & replace(GLS_NameTaken, "%NAME%", sUserName) & "<BR>"

Response.Write GLS_TryAgain & gsAuctionTextClose & "</P>"

Else

Call InsertUser

End If

CountRS.Close

set CountRS = Nothing

End Sub

Sub InsertUser

Randomize

sPassword = clng(rnd * 1000000) + 1000

Response.Write "<P ALIGN=""CENTER"">" & gsAuctionTextOpen & GLS_RegistrationSuccessMsg & "<BR>"

SendPassEmail(sPassword)

Response.Write GLS_PasswordEmailed & "<BR>"

Response.Write GLS_ChangePasswordInstruction & "<BR>"

Response.Write GLS_ClickToContinue & gsAuctionTextClose & "</P>"

End Sub

function CalculaCPF()

Dim RecebeCPF, Numero(11), soma, resultado1, resultado2

RecebeCPF = Request("CPF")

'Retirar todos os caracteres que não sejam 0-9

s=""

for x=1 to len(RecebeCPF)

ch=mid(RecebeCPF,x,1)

if asc(ch)>=48 and asc(ch)<=57 then

s=s & ch

end if

next

RecebeCPF = s

if len(RecebeCPF) <> 11 then

response.write("<h1>&Eacute; obrigat&oacute;rio o CPF com 11 d&iacute;gitos</h1>")

elseif RecebeCPF = "00000000000" then

response.write("<h1>CPF Inválido</h1>")

else

Numero(1) = Cint(Mid(RecebeCPF,1,1))

Numero(2) = Cint(Mid(RecebeCPF,2,1))

Numero(3) = Cint(Mid(RecebeCPF,3,1))

Numero(4) = Cint(Mid(RecebeCPF,4,1))

Numero(5) = Cint(Mid(RecebeCPF,5,1))

Numero(6) = CInt(Mid(RecebeCPF,6,1))

Numero(7) = Cint(Mid(RecebeCPF,7,1))

Numero(8) = Cint(Mid(RecebeCPF,8,1))

Numero(9) = Cint(Mid(RecebeCPF,9,1))

Numero(10) = Cint(Mid(RecebeCPF,10,1))

Numero(11) = Cint(Mid(RecebeCPF,11,1))

soma = 10 * Numero(1) + 9 * Numero(2) + 8 * Numero(3) + 7 * Numero(4) + 6 * Numero(5) + 5 * Numero(6) + 4 * Numero(7) + 3 * Numero(8) + 2 * Numero(9)

soma = soma -(11 * (int(soma / 11)))

if soma = 0 or soma = 1 then

resultado1 = 0

else

resultado1 = 11 - soma

end if

if resultado1 = Numero(10) then

soma = Numero(1) * 11 + Numero(2) * 10 + Numero(3) * 9 + Numero(4) * 8 + Numero(5) * 7 + Numero(6) * 6 + Numero(7) * 5 + Numero(8) * 4 + Numero(9) * 3 + Numero(10) * 2

soma = soma -(11 * (int(soma / 11)))

if soma = 0 or soma = 1 then

resultado2 = 0

else

resultado2 = 11 - soma

end if

npSQL = "INSERT INTO tblQARegistration (regUserName, regPassword, regValidated, regName, anonasc, mesnasc, dianasc, regEmail, " & _

"regSexo, regBairro1, regBairro2, regAddress1, regAddress2,regFone,regDdd1, regCel, regDdd2, regCPF, regCity, regState, regZip, Infoad, Novidades, regCountry) VALUES (" & _

SQLStr(sUserName) & ", " & _

SQLStr(sPassword) & " , " & _

SQLBool(gbUsersAdd) & ", " & _

SQLStr(sName) & ", " & _

SQLStr(sAnonasc) & ", " & _

SQLStr(sMesnasc) & ", " & _

SQLStr(sDianasc) & ", " & _

SQLStr(sEmail) & ", " & _

SQLStr(sSexo) & ", " & _

SQLStr(sAddressOne) & ", " & _

SQLStr(sBairro1) & ", " & _

SQLStr(sAddressTwo) & ", " & _

SQLStr(sBairro2) & ", " & _

SQLStr(sfone) & ", " & _

SQLStr(sDdd1) & ", " & _

SQLStr(sCel) & ", " & _

SQLStr(sDdd2) & ", " & _

SQLStr(sCPF) & ", " & _

SQLStr(sCity) & ", " & _

SQLStr(sState) & ", " & _

SQLStr(sZip) & "," & _

SQLStr(sInfoad) & "," & _

SQLStr(sNovidades) & "," & _

SQLStr(sCountry) & " )"

gobjConnect.Execute(npSQL)

if resultado2 = Numero(11) then

response.write("<h1>CPF Válido</h1>")

else

response.write("<h1>CPF Inválido</h1>")

end if

else

response.write("<h1>CPF Inválido</h1>")

end if

end if

end function

Sub SendPassEmail(sPass)

sBody = "" & ReadFile(Server.MapPath("QAEmailTemplates\QANewUserRegister.txt"))

sBody = Replace(sBody, "%USERNAME%", sUserName)

sBody = Replace(sBody, "%PASS%", sPass)

sBody = Replace(sBody, "%AUCPATH%", gsAucURL)

sBody = sBody & Chr(13) & Chr(10) & "Bekan© todos os direitos reservados"

sSubject = GetFirstLine(sBody)

SendEmailMessage sEmail, gsAdminEmail, sSubject, sBody

End Sub

%>

cara eu realmente não sei mais o que eu faço

Link para o comentário
Compartilhar em outros sites

  • 0

cara veio uma luz maravilhosa na minha mente e ai eu consegui barrar o registro mas agora o código ficou assim

<!-- #include file="config.asp" -->

<%

'***********************************************************

'* Desenvolvido por Francisco Biscaino Fone (15) 97069875 *

'* Todos os direitos Reservados *

'***********************************************************

sUserName = "" & RequestValue("username")

sName = "" & RequestValue("name")

sEmail = "" & RequestValue("email")

sDianasc = "" & RequestValue("Dianasc")

sMesnasc = "" & RequestValue("Mesnasc")

sAnonasc = "" & RequestValue ("Anonasc")

sSexo = "" & RequestValue("Sexo")

sAddressOne = "" & RequestValue("addressone")

sBairro1 = "" & RequestValue("Bairro1")

sAddressTwo = "" & RequestValue("addresstwo")

sBairro2 = "" & RequestValue("Bairro2")

sFone = "" & RequestValue("fone")

sDdd1 = "" & RequestValue("ddd1")

sCel = "" & RequestValue ("cel")

sDdd2 = "" & RequestValue("ddd2")

sCPF = "" & RequestValue("CPF")

sCity = "" & RequestValue("city")

sState = "" & RequestValue("state")

sZip = "" & RequestValue("zip")

sCountry = "" & RequestValue("country")

sInfoad = "" & RequestValue("Infoad")

sNovidades = "" & RequestValue("Novidades")

sString = ""

OpenDBConn

DoPageHeader

If Len(Trim(sUserName)) = 0 Then

sString = sString & ErrorString(GLS_UserNameDet)

End If

If Len(Trim(sName)) = 0 Then

sString = sString & ErrorString(GLS_Name)

End If

If Len(Trim(sEmail)) = 0 Then

sString = sString & ErrorString(GLS_Email)

End If

If Len(Trim(sAddressOne)) = 0 AND gbReqAddress Then

sString = sString & ErrorString(GLS_AddressOne)

End If

If Len(Trim(sCPF)) = 0 AND gbReqCPF Then

sString = sString & ErrorString(GLS_CPF)

End If

If Len(Trim(sCity)) = 0 AND gbReqCity Then

sString = sString & ErrorString(GLS_City)

End If

If Len(Trim(sState)) = 0 AND gbReqState Then

sString = sString & ErrorString(GLS_State)

End If

If Len(Trim(sZip)) = 0 AND gbReqZip Then

sString = sString & ErrorString(GLS_Zip)

End If

If Len(Trim(sCountry)) = 0 AND gbReqCountry Then

sString = sString & ErrorString(GLS_Country)

End If

If sString <> "" Then

Response.Write "<CENTER>" & gsErrorTextOpen & sString & "<BR>" & GLS_GoBack & gsErrorTextClose & "</CENTER>"

Else

CheckName

End If

DoPageFooter

Function ErrorString(sField)

ErrorString = replace(GLS_FieldErr,"%FIELDNAME%","<B>" & UCASE(sField) & "</B>") & "<BR>"

End Function

Sub CheckName

sSQL = sSQL & "SELECT COUNT(*) as Total FROM tblQARegistration WHERE regUserName = " & SQLStr(sUserName)

Set CountRS = gobjConnect.Execute(sSQL)

If CountRS.Fields("Total") > 0 Then

Response.Write "<P ALIGN=""CENTER"">" & gsAuctionTextOpen & replace(GLS_NameTaken, "%NAME%", sUserName) & "<BR>"

Response.Write GLS_TryAgain & gsAuctionTextClose & "</P>"

Else

Call calculacpf

End If

CountRS.Close

set CountRS = Nothing

End Sub

function CalculaCPF()

Dim RecebeCPF, Numero(11), soma, resultado1, resultado2

RecebeCPF = Request("CPF")

'Retirar todos os caracteres que não sejam 0-9

s=""

for x=1 to len(RecebeCPF)

ch=mid(RecebeCPF,x,1)

if asc(ch)>=48 and asc(ch)<=57 then

s=s & ch

end if

next

RecebeCPF = s

if len(RecebeCPF) <> 11 then

response.write("<h1>&Eacute; obrigat&oacute;rio o CPF com 11 d&iacute;gitos</h1>")

elseif RecebeCPF = "00000000000" then

response.write("<h1>CPF Inválido</h1>")

else

Numero(1) = Cint(Mid(RecebeCPF,1,1))

Numero(2) = Cint(Mid(RecebeCPF,2,1))

Numero(3) = Cint(Mid(RecebeCPF,3,1))

Numero(4) = Cint(Mid(RecebeCPF,4,1))

Numero(5) = Cint(Mid(RecebeCPF,5,1))

Numero(6) = CInt(Mid(RecebeCPF,6,1))

Numero(7) = Cint(Mid(RecebeCPF,7,1))

Numero(8) = Cint(Mid(RecebeCPF,8,1))

Numero(9) = Cint(Mid(RecebeCPF,9,1))

Numero(10) = Cint(Mid(RecebeCPF,10,1))

Numero(11) = Cint(Mid(RecebeCPF,11,1))

soma = 10 * Numero(1) + 9 * Numero(2) + 8 * Numero(3) + 7 * Numero(4) + 6 * Numero(5) + 5 * Numero(6) + 4 * Numero(7) + 3 * Numero(8) + 2 * Numero(9)

soma = soma -(11 * (int(soma / 11)))

if soma = 0 or soma = 1 then

resultado1 = 0

else

resultado1 = 11 - soma

end if

if resultado1 = Numero(10) then

soma = Numero(1) * 11 + Numero(2) * 10 + Numero(3) * 9 + Numero(4) * 8 + Numero(5) * 7 + Numero(6) * 6 + Numero(7) * 5 + Numero(8) * 4 + Numero(9) * 3 + Numero(10) * 2

soma = soma -(11 * (int(soma / 11)))

if soma = 0 or soma = 1 then

resultado2 = 0

else

resultado2 = 11 - soma

end if

if resultado2 = Numero(11) then

else

Call checkcpf

response.write("<h1>CPF Inválido</h1>")

end if

else

response.write("<h1>CPF Inválido</h1>")

end if

end if

end function

Sub CheckCPF

sSQL = sSQL & "SELECT COUNT(*) as Total FROM tblQARegistration WHERE regCPF = " & SQLStr(sCPF)

Set CountRS = gobjConnect.Execute(sSQL)

If CountRS.Fields("Total") > 0 Then

Response.Write "<P ALIGN=""CENTER"">" & gsAuctionTextOpen & replace(GLS_CPFTaken, "%CPF%", sCPF) & "<BR>"

Response.Write GLS_TryAgain & gsAuctionTextClose & "</P>"

Else

Call InsertUser

End If

CountRS.Close

set CountRS = Nothing

End Sub

Sub InsertUser

Randomize

sPassword = clng(rnd * 1000000) + 1000

npSQL = "INSERT INTO tblQARegistration (regUserName, regPassword, regValidated, regName, anonasc, mesnasc, dianasc, regEmail, " & _

"regSexo, regBairro1, regBairro2, regAddress1, regAddress2,regFone,regDdd1, regCel, regDdd2, regCPF, regCity, regState, regZip, Infoad, Novidades, regCountry) VALUES (" & _

SQLStr(sUserName) & ", " & _

SQLStr(sPassword) & " , " & _

SQLBool(gbUsersAdd) & ", " & _

SQLStr(sName) & ", " & _

SQLStr(sAnonasc) & ", " & _

SQLStr(sMesnasc) & ", " & _

SQLStr(sDianasc) & ", " & _

SQLStr(sEmail) & ", " & _

SQLStr(sSexo) & ", " & _

SQLStr(sAddressOne) & ", " & _

SQLStr(sBairro1) & ", " & _

SQLStr(sAddressTwo) & ", " & _

SQLStr(sBairro2) & ", " & _

SQLStr(sfone) & ", " & _

SQLStr(sDdd1) & ", " & _

SQLStr(sCel) & ", " & _

SQLStr(sDdd2) & ", " & _

SQLStr(sCPF) & ", " & _

SQLStr(sCity) & ", " & _

SQLStr(sState) & ", " & _

SQLStr(sZip) & "," & _

SQLStr(sInfoad) & "," & _

SQLStr(sNovidades) & "," & _

SQLStr(sCountry) & " )"

gobjConnect.Execute(npSQL)

Response.Write "<P ALIGN=""CENTER"">" & gsAuctionTextOpen & GLS_RegistrationSuccessMsg & "<BR>"

SendPassEmail(sPassword)

Response.Write GLS_PasswordEmailed & "<BR>"

Response.Write GLS_ChangePasswordInstruction & "<BR>"

Response.Write GLS_ClickToContinue & gsAuctionTextClose & "</P>"

End Sub

Sub SendPassEmail(sPass)

sBody = "" & ReadFile(Server.MapPath("QAEmailTemplates\QANewUserRegister.txt"))

sBody = Replace(sBody, "%USERNAME%", sUserName)

sBody = Replace(sBody, "%PASS%", sPass)

sBody = Replace(sBody, "%AUCPATH%", gsAucURL)

sBody = sBody & Chr(13) & Chr(10) & "Bekan© todos os direitos reservados"

sSubject = GetFirstLine(sBody)

SendEmailMessage sEmail, gsAdminEmail, sSubject, sBody

End Sub

%>

agora o que eu presciso é simples mas eu ainda não consegui fazer é o seguinte

na função do cpf eu presciso chamar o sub checkcpf para dar a continuidade do registro

agora ta ficando como eu quero que fique

Link para o comentário
Compartilhar em outros sites

  • 0

Cara, pra quer complicar tanto assim.

Faz assim. na pagina onde você pega os dados do cliente, CPF, NOME, ENDEREÇO, ETC. você faz uma verificação do cpf através de javascript. Colocando o formulária para enviar para a pagina .asp q pega os dados do cliente somente se o cpf for válido.

Agora a segunda parte: Verificar se o cpf já esta cadastrado no seu Bd.

você concorda comigo q para chegar na pagina q cadastra no Bd você ter q ter passado com CPF válido na pagina do formulário Correto. então agora e so você capturar todos os dados do Campos do seu formulário, mas somente captura.

Em seguida você pega somente o numero do CPF e faz um "select CPF Nome_Tabela"

E joga numa condição if

If rs.BOF=rs.EOF then

Mensagem="CPF já cadastrado"

response.redirct("cadastrado.asp")

Else

Coloca daqui em diante o codigo para cadastrar no seu bd.

End if

ABAIXO VAI O CODIGO JAVASCRIPT ( Lembrando no seu submit do form coloca onsubmit="submete();" beleza!! )

-------------------------------------------------------------

Código Javascript para valida CPF

<script language="javascript">

function submete () {if (checacpf(document.form1.cpf.value))

{document.form1.submit();}else

{errors="1";if (errors) alert('CPF invalido, por favor digite-o novamente.');

document.retorno = (errors == '');}}

function checacpf (cpf)

{if (cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999")

return false;

soma = 0;

for (i=0; i < 9; i ++)

soma += parseInt(cpf.charAt(i)) * (10 - i);

resto = 11 - (soma % 11);

if (resto == 10 || resto == 11)

resto = 0;

if (resto != parseInt(cpf.charAt(9)))

return false;

soma = 0;

for (i = 0; i < 10; i ++)

soma += parseInt(cpf.charAt(i)) * (11 - i);

resto = 11 - (soma % 11);

if (resto == 10 || resto == 11)

resto = 0;

if (resto != parseInt(cpf.charAt(10)))

return false;

alert('CPF correto.');return true;}

</script>

não sei se e entendi bem sua duvida mas espero q ajude! beleza!!

Link para o comentário
Compartilhar em outros sites

  • 0

o sistema de validação ele funciona o meu problema mesmo era barrar o cara p/ que ele não fosse inscrito no bd como eu falei anteriormente eu consegui fazer isto o que eu presciso realmente agora é na função do cpf ao ver que o cpf não tem problemas mandar para a parte de inserção de usuário e se tem problemas ele não passar para a inserção

Link para o comentário
Compartilhar em outros sites

  • 0

o que quero fazer agora é bem simpls pois eu percebi um jeito de fazer isto funcionar como eu quero

se o cpf é válido na função calcula cfp ela vai e chama o a sub checkcpf

e for inválido a fução não chama ninguém

o ultimo código que eu enviei é como esta ele num todo agora ele agora esta melhor mas somente falta esta parte funcionar desta forma e ai vai ficar beleza mesmo

e no termino eu quero disponibilizar p/ a galera o sistema de form que esta saíndo aqui

function CalculaCPF()

Dim RecebeCPF, Numero(11), soma, resultado1, resultado2

RecebeCPF = Request("CPF")

'Retirar todos os caracteres que não sejam 0-9

s=""

for x=1 to len(RecebeCPF)

ch=mid(RecebeCPF,x,1)

if asc(ch)>=48 and asc(ch)<=57 then

s=s & ch

end if

next

RecebeCPF = s

if len(RecebeCPF) <> 11 then

response.write("<h1>&Eacute; obrigat&oacute;rio o CPF com 11 d&iacute;gitos</h1>")

elseif RecebeCPF = "00000000000" then

response.write("<h1>CPF Inválido</h1>")

else

Numero(1) = Cint(Mid(RecebeCPF,1,1))

Numero(2) = Cint(Mid(RecebeCPF,2,1))

Numero(3) = Cint(Mid(RecebeCPF,3,1))

Numero(4) = Cint(Mid(RecebeCPF,4,1))

Numero(5) = Cint(Mid(RecebeCPF,5,1))

Numero(6) = CInt(Mid(RecebeCPF,6,1))

Numero(7) = Cint(Mid(RecebeCPF,7,1))

Numero(8) = Cint(Mid(RecebeCPF,8,1))

Numero(9) = Cint(Mid(RecebeCPF,9,1))

Numero(10) = Cint(Mid(RecebeCPF,10,1))

Numero(11) = Cint(Mid(RecebeCPF,11,1))

soma = 10 * Numero(1) + 9 * Numero(2) + 8 * Numero(3) + 7 * Numero(4) + 6 * Numero(5) + 5 * Numero(6) + 4 * Numero(7) + 3 * Numero(8) + 2 * Numero(9)

soma = soma -(11 * (int(soma / 11)))

if soma = 0 or soma = 1 then

resultado1 = 0

else

resultado1 = 11 - soma

end if

if resultado1 = Numero(10) then

soma = Numero(1) * 11 + Numero(2) * 10 + Numero(3) * 9 + Numero(4) * 8 + Numero(5) * 7 + Numero(6) * 6 + Numero(7) * 5 + Numero(8) * 4 + Numero(9) * 3 + Numero(10) * 2

soma = soma -(11 * (int(soma / 11)))

if soma = 0 or soma = 1 then

resultado2 = 0

else

resultado2 = 11 - soma

end if

if resultado2 = Numero(11) then

else

response.write("<h1>CPF Inválido</h1>")

end if

else

response.write("<h1>CPF Inválido</h1>")

end if

end if

end function

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152k
    • Posts
      651,8k
×
×
  • Criar Novo...