VB.NET代碼驗(yàn)證信用卡卡號是否正確,本代碼使用luhn算法驗(yàn)證
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 |
Dim creditCardNumber As String creditCardNumber = "1234567891234563" '這里請自行輸入你要驗(yàn)證的號碼 If creditCardNumber.Length < 16 Then Page.ClientScript.RegisterStartupScript( Me . GetType (), "dd" , "alert('錯(cuò)誤數(shù)字只有" & 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 '偶數(shù)乘1奇數(shù)乘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('錯(cuò)誤);" , True ) End If End If |
以上所述就是本文的全部內(nèi)容了,希望對大家學(xué)習(xí)vb.net能夠有所幫助。
![]() | ![]() .. 定價(jià):¥225 優(yōu)惠價(jià):¥213 更多書籍 |
![]() | ![]() .. 定價(jià):¥133 優(yōu)惠價(jià):¥133.0 更多書籍 |