how to validate a textbox in windows

Posted by Shanky11 under C# on 3/1/2013 | Points: 10 | Views : 895 | Status : [Member] | Replies : 3
i want this code to convert n vb.net
how to write null in vb.net


private void txtPassword_Validating(object sender, CancelEventArgs e)
{
if (string.IsNullOrEmpty(txtPassword.Text))
{
errorProvider1.SetError(txtPassword, "Password required!");
}
else if (!Regex.IsMatch(txtPassword.Text, @"[A-Za-z][A-Za-z0-9]{2,7}"))
{
errorProvider1.SetError(txtPassword, "Password invalid!");
}
else
{
errorProvider1.SetError(txtPassword, null);
}
}




Responses

Posted by: Satyapriyanayak on: 3/1/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If String.IsNullOrEmpty(txtPassword.Text) Then
ErrorProvider1.SetError(txtPassword, "Password required!")
ElseIf Not Regex.IsMatch(txtPassword.Text, "[A-Za-z][A-Za-z0-9]{2,7}") Then
ErrorProvider1.SetError(txtPassword, "Password invalid!")
Else
ErrorProvider1.SetError(txtPassword, Nothing)
End If
End Sub
End Class



If this post helps you mark it as answer
Thanks

If this post helps you mark it as answer
Thanks

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shanky11 on: 3/1/2013 [Member] Starter | Points: 25

Up
0
Down
hello stayapriyank
i have tried this it is runing but on error blink error message is not showing


Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raj.Trivedi on: 3/1/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Imports System
Private Sub txtPassword_Validating(ByVal sender As Object, ByVal e As CancelEventArgs)
If String.IsNullOrEmpty(txtPassword.Text) Then
errorProvider1.SetError(txtPassword, "Password required!")
Else If Not Regex.IsMatch(txtPassword.Text,"[A-Za-z][A-Za-z0-9]{2,7}") Then
errorProvider1.SetError(txtPassword, "Password invalid!")
Else
errorProvider1.SetError(txtPassword, Nothing)
End If
End Sub


Regard's
Raj.Trivedi
"Sharing is Caring"
Please mark as answer if your Query is resolved

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response