【发布时间】:2017-02-24 11:28:17
【问题描述】:
如描述中所述,我需要验证用户输入以确保其长度至少为 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
【问题讨论】:
标签: validation input basic