Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regular exression

Status
Not open for further replies.

angela4eva

Programmer
Apr 29, 2005
46
US
I need to write a regular expression in vb.net
i have field whose vlue is stored in variable
var1
i want to make sure that the value is in the format
<text>.<text>ex:address.086
the regular expression must make sure that the value is in this format
that is check that the first part is a textfollowed by a period and then number,if the last part is like 086 then convert it to 86 if it is text like myname then it should give an error. help appreciated
thanks
 
you could try something like this:

Code:
  Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

    CheckBox1.Checked = False
    Dim rx As New System.Text.RegularExpressions.Regex("[a-zA-Z]{1,}\.\d{1,}")
    Dim m As System.Text.RegularExpressions.Match = rx.Match(TextBox1.Text)
    CheckBox1.Checked = m.Success
    If m.Success Then
      TextBox1.Text = rx.Replace(TextBox1.Text, "\.0", ".")
    End If

  End Sub

Hope this helps.

[vampire][bat]
 
A slight enhancement:

Code:
    CheckBox1.Checked = False
    Dim MainPattern As String = "[a-zA-Z]{1,}\.\d{1,}"
    Dim rx As New System.Text.RegularExpressions.Regex(MainPattern)
    Dim m As System.Text.RegularExpressions.Match = rx.Match(TextBox1.Text)
    If m.Success Then
      TextBox1.Text = rx.Replace(TextBox1.Text, "\.(0){1,}", ".")
      're-check to make sure that the number part didn't contain all 0s
      CheckBox1.Checked = rx.Match(TextBox1.Text, MainPattern).Success
    End If


[vampire][bat]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top