如描述中所述,我需要驗證用戶輸入以確保它至少包含6個字符並且包含1個數字字符和字母表中的1個字符。驗證輸入有問題。需要驗證是否至少有一個數字字符和一個字母字符
到目前爲止,我已經得到了長度驗證工作,但似乎無法讓我的數字驗證正常工作。如果除了數字之外什麼都不輸入,它可以工作,但是如果我把字母放在IE abc123中,它將不會識別出有數字存在。
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If txtPassword.TextLength < 6 Then
lblError.Text = "Sorry that password is too short."
ElseIf txtPassword.TextLength >= 6 Then
Dim intCheck As Integer = 0
Integer.TryParse(txtPassword.Text, intCheck)
If Integer.TryParse(txtPassword.Text, intCheck) Then
lblError.Text = "Password set!"
Else
lblError.Text = "Password contains no numeric characters"
End If
End If
End Sub
End Class
使用此http://stackoverflow.com/a/14850765/1890983 –