|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Validation ControlsHi
I am looking for validation controls for email, URL etc. similar to those provided by ASP.NET 2005 Thank you, Samuel Samuel Shulman wrote:
> Hi You can use reg expressions to see if the contents of the control is a> > I am looking for validation controls for email, URL etc. similar to those > provided by ASP.NET 2005 > > Thank you, > Samuel valid emai, url, etc. dag regurlar expressions vb.net Thanks,
All I found is the MaskedTextBox control and the Mask property which doesn't have a mask for email or URL address Cheers, Samuel <fallen.mor***@gmail.com> wrote in message Show quoteHide quote news:1166501147.083230.308890@48g2000cwx.googlegroups.com... > > Samuel Shulman wrote: >> Hi >> >> I am looking for validation controls for email, URL etc. similar to those >> provided by ASP.NET 2005 >> >> Thank you, >> Samuel > > You can use reg expressions to see if the contents of the control is a > valid emai, url, etc. > > dag regurlar expressions vb.net > Samuel Shulman wrote:
> Thanks, You can write a class that inherits the MaskedTextbox and uses regular> > All I found is the MaskedTextBox control and the Mask property which doesn't > have a mask for email or URL address > > Cheers, > Samuel > expressions for validation. It's pretty easy. Here's an old piece of code I found for doing that: (It could probably use a bit of work though - I have a newer version, but not on this computer) ''' <summary> ''' This class is a text box that will make sure that its input only contains text matching its ''' regular expression. ''' </summary> ''' <remarks>If the user attempts to enter a character that causes the text to not match the ''' regular expression, then the text will be reverted to what it was before the user's action.</remarks> Public Class regexpTextBox Inherits System.Windows.Forms.TextBox Protected myRegex As New System.Text.RegularExpressions.Regex(".*", System.Text.RegularExpressions.RegexOptions.Compiled) Protected myRegexStr As String Protected myStr As String = "" ''' <summary> ''' Gets or sets the string representation of this regexpTextBox. ''' </summary> Overridable Property regex() As String Get Return myRegexStr End Get Set(ByVal value As String) If value <> "" Then myRegexStr = value myRegex = New System.Text.RegularExpressions.Regex(myRegexStr, System.Text.RegularExpressions.RegexOptions.Compiled) End If End Set End Property ''' <summary> ''' This procedure is used to check if this TextBox's text matches its regular expression. ''' </summary> ''' <remarks>If the match is unsuccessful, then text will not be updated.</remarks> Public Overridable Sub match() Dim myMatch As System.Text.RegularExpressions.Match = myRegex.Match(Me.Text) If myMatch.Success Then myStr = Me.Text Else Me.Text = myStr 'MsgBox("You must match: " & myRegexStr, MsgBoxStyle.Exclamation, "RegexpTextBox") End If End Sub Private Sub regexpTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.TextChanged Me.match() End Sub End Class Thank you,
Samuel <lord.zol***@gmail.com> wrote in message Show quoteHide quote news:1166539618.970148.93800@79g2000cws.googlegroups.com... > > Samuel Shulman wrote: >> Thanks, >> >> All I found is the MaskedTextBox control and the Mask property which >> doesn't >> have a mask for email or URL address >> >> Cheers, >> Samuel >> > You can write a class that inherits the MaskedTextbox and uses regular > expressions for validation. It's pretty easy. > > Here's an old piece of code I found for doing that: > (It could probably use a bit of work though - I have a newer version, > but not on this computer) > > > ''' <summary> > ''' This class is a text box that will make sure that its input only > contains text matching its > ''' regular expression. > ''' </summary> > ''' <remarks>If the user attempts to enter a character that causes the > text to not match the > ''' regular expression, then the text will be reverted to what it was > before the user's action.</remarks> > Public Class regexpTextBox > Inherits System.Windows.Forms.TextBox > > Protected myRegex As New System.Text.RegularExpressions.Regex(".*", > System.Text.RegularExpressions.RegexOptions.Compiled) > > Protected myRegexStr As String > Protected myStr As String = "" > > ''' <summary> > ''' Gets or sets the string representation of this regexpTextBox. > ''' </summary> > Overridable Property regex() As String > Get > Return myRegexStr > End Get > Set(ByVal value As String) > If value <> "" Then > myRegexStr = value > myRegex = New > System.Text.RegularExpressions.Regex(myRegexStr, > System.Text.RegularExpressions.RegexOptions.Compiled) > End If > End Set > End Property > > ''' <summary> > ''' This procedure is used to check if this TextBox's text matches > its regular expression. > ''' </summary> > ''' <remarks>If the match is unsuccessful, then text will not be > updated.</remarks> > Public Overridable Sub match() > Dim myMatch As System.Text.RegularExpressions.Match = > myRegex.Match(Me.Text) > If myMatch.Success Then > myStr = Me.Text > Else > Me.Text = myStr > 'MsgBox("You must match: " & myRegexStr, > MsgBoxStyle.Exclamation, "RegexpTextBox") > End If > End Sub > > Private Sub regexpTextBox_TextChanged(ByVal sender As Object, ByVal > e As System.EventArgs) Handles Me.TextChanged > Me.match() > End Sub > End Class > |
|||||||||||||||||||||||