none
Regex for comma separated strings

    Question

  • Hi all, I am trying to write a regex for a comma delimited strings, It should be accepting any string of format ( Name,Name) and name should be alpha.

    One more thing is this regex validation should happen only if one particular listitem of a radiobuttonlist is selected and should not do validation for other listitems, my concern is i should do it without javascript. Help me with this guys.

    Thanks in advance,

    Ricky

    Thursday, June 06, 2013 2:15 AM

Answers

  • You can use the string.split method to separate things in a comma delimited list.

    Option Strict On
    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim TestString As String = "item1=99,item2=12aq,item3=somevalue,item4=etc,item5=blah,item6=???,item7,item8=,item9=???,item10=???"
            Dim Items As List(Of String) = TestString.Split(","c).ToList
            For Each item As String In Items
                Dim parts() As String = item.Split("="c)
                Dim FieldName As String = String.Empty
                Dim FieldValue As String = "Null"
                If parts.Count > 0 Then FieldName = parts(0)
                If parts.Count > 1 Then FieldValue = parts(1)
                Dim msg As String = "The value for " & FieldName & " is: " & FieldValue
                MsgBox(msg)
            Next
        End Sub
    End Class
    


    “If you want something you've never had, you need to do something you've never done.”

    Don't forget to mark helpful posts and answers ! Answer an interesting question? Write a new article about it! My Articles
    *This post does not reflect the opinion of Microsoft, or its employees.

    Thursday, June 06, 2013 6:04 AM

All replies

  • What would you like this regex to do ?

    Why mention javascript in a VB .NET forum ?

    Thursday, June 06, 2013 3:54 AM
  • 1. How do you know regex is the best approach for what you want to do?

    2. The information in your post for what you want to do is unable to be comprehended and makes no sense to me. Please edit your original post and take your time to fully explain what you want to do. Or don't.


    You've taught me everything I know but not everything you know.

    Thursday, June 06, 2013 5:44 AM
  • You can use the string.split method to separate things in a comma delimited list.

    Option Strict On
    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim TestString As String = "item1=99,item2=12aq,item3=somevalue,item4=etc,item5=blah,item6=???,item7,item8=,item9=???,item10=???"
            Dim Items As List(Of String) = TestString.Split(","c).ToList
            For Each item As String In Items
                Dim parts() As String = item.Split("="c)
                Dim FieldName As String = String.Empty
                Dim FieldValue As String = "Null"
                If parts.Count > 0 Then FieldName = parts(0)
                If parts.Count > 1 Then FieldValue = parts(1)
                Dim msg As String = "The value for " & FieldName & " is: " & FieldValue
                MsgBox(msg)
            Next
        End Sub
    End Class
    


    “If you want something you've never had, you need to do something you've never done.”

    Don't forget to mark helpful posts and answers ! Answer an interesting question? Write a new article about it! My Articles
    *This post does not reflect the opinion of Microsoft, or its employees.

    Thursday, June 06, 2013 6:04 AM