VB.NET實現(xiàn)驗證信用卡卡號
更新時間:2015年05月18日 11:35:00 投稿:hebedich
這篇文章主要介紹了VB.NET實現(xiàn)驗證信用卡卡號是否正確的代碼,主要根據(jù)luhn算法來驗證,有需要的小伙伴可以參考下。
VB.NET代碼驗證信用卡卡號是否正確,本代碼使用luhn算法驗證
Dim creditCardNumber As String creditCardNumber = "1234567891234563" '這里請自行輸入你要驗證的號碼 If creditCardNumber.Length < 16 Then Page.ClientScript.RegisterStartupScript(Me.GetType(), "dd", "alert('錯誤數(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('錯誤);", True) End If End If
以上所述就是本文的全部內(nèi)容了,希望對大家學習vb.net能夠有所幫助。
相關(guān)文章
VB.NET中使用種子填充算法實現(xiàn)給圖片著色的例子
這篇文章主要介紹了VB.NET中使用種子填充算法實現(xiàn)給圖片著色的例子,在開發(fā)一個畫圖工具時遇到的問題,需要的朋友可以參考下2014-07-07