日期:2014-05-19  浏览次数:20826 次

textBox的验证问题
我用的是vs2003,做的是winform,想在textbox里做一个邮箱和网站的验证,网上查了些资料说要添加验证控件然后添加正则表达式就行,但实在找不到哪有验证控件,哪些仁兄贴下代码,谢谢``

------解决方案--------------------
'检测邮箱
Public Sub Dataemail(ByVal email As String)
el = Len(email)
pos1 = email.IndexOfAny( "@ ")
pos2 = email.IndexOfAny( ". ")
If (pos1 > = 1 And pos2 > = 3 And el > pos2 + 1) Then
j = "OK "
Else
MessageBox.Show( "你输入的邮箱不正确! ", "Data Entry Error ", _
+MessageBoxButtons.OK, MessageBoxIcon.Error)
txtemail.Text = " "
txtemail.Focus()
End If
End Sub
------解决方案--------------------
Regex myreg = new Regex(@ "^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$ "); //email验证
if (!myreg.IsMatch(email.Text))
{
err += "邮件格式不正确!\r\n ";
}