欢迎来到工商注册核名查询系统!

vb

当前位置:主页 > 软件编程 > vb >

VB.NET实现验证信用卡卡号

来源:本站原创|时间:2022-11-25|栏目:vb|

VB.NET代码验证信用卡卡号是否正确,本代码使用luhn算法验证

Dim creditCardNumber As String
creditCardNumber = "1234567891234563" '这里请自行输入你要验证的号码
If creditCardNumber.Length < 16 Then
  Page.ClientScript.RegisterStartupScript(Me.GetType(), "dd", "alert('错误数字只有" & creditCardNumber.Length & "碼');", True)
Else
  Dim Int(15) As Integer
  Dim x, num, sun As Integer
  For x = 0 To 15
    num = creditCardNumber.Substring(x, 1)
    If (x + 1) Mod 2 <> 0 Then '偶数乘1奇数乘2
      Int(x) = num * 2
    Else
      Int(x) = num
    End If
  Next
  For x = 0 To 15
    If (Int(x) > 9) Then
      Int(x) = (Int(x) Mod 10) + 1
    End If
    sun += Int(x)
  Next
  If (sun Mod 10 = 0) Then
    Page.ClientScript.RegisterStartupScript(Me.GetType(), "ddd", "alert('正确的信用卡');", True)
  Else
    Page.ClientScript.RegisterStartupScript(Me.GetType(), "dd", "alert('错误);", True)
  End If
End If

以上所述就是本文的全部内容了,希望对大家学习vb.net能够有所帮助。

更多vb

您可能感兴趣的文章

阅读排行

本栏相关

随机阅读

网页制作CMS教程网络编程软件编程脚本语言数据库服务器

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:835971066 | 邮箱:835971066#qq.com(#换成@)

Copyright © 2002-2020 工商注册核名查询系统 版权所有