VB.net文本框只允许输入数字与. 利用正则表达式验证IP地址
文本框只允许输入数字或 . 并且验证IP地址输入是否合法 If Not System.Text.RegularExpressions.Regex.IsMatch(Me.txtIP.Text,"^/d{1,3}/./d{1,3}$") Then CCDC.Utility.msg.ShowWarning("服务器地址输入不正确。") Me.txtIP.Focus() Return False End If
输入的是否是数字或. Private Sub txtIP_KeyPress(ByVal sender As System.Object,ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtIP.KeyPress e.Handled = True If System.Text.RegularExpressions.Regex.IsMatch(e.KeyChar,"^[0-9]|/.$") OrElse (Asc(e.KeyChar) = Keys.Back) Then e.Handled = False End If End Sub (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |