Thursday, June 27, 2013

Validate TextBox For Digits and Texts VB.NET


imports System.Text.RegularExpressions

 // For Text Only

 If Not Regex.Match(TextBox1.Text, "^[a-z]*$", RegexOptions.IgnoreCase).Success Then
    MsgBox("Please enter text only.")
    TextBox1.Focus()
  End If


// For Digits Only 

 If Not Regex.Match(TextBox1.Text, "^[0-9]*$", RegexOptions.IgnoreCase).Success Then
    MsgBox("Please enter Digits only.")
    TextBox1.Focus()
  End If

No comments: