Question

I have a textbox in which a user can type comma separated email addresses. User can only email within a specific domain defined in the regular expression. Currently, I am validating the input by using

If Regex.IsMatch(txtEmailto.Text.Trim, "\b\w+(@abc.com)\b") = False Then MsgBox("Please enter a valid Send Email to") Exit Sub

My regular expression is working for the first email address in the textbox but nothing after the comma. I would like to get the regular expression so that it would go through all the text and return false if any of the email address are outside of abc.com domain.

Was it helpful?

Solution

    Dim emails As String() = txtEmailto.Text.Split(",")
    For Each email As String In emails
        If Regex.IsMatch(email.Trim, "\b\w+(@abc.com)\b") = False Then
            MsgBox("Please enter a valid Send Email to")
            Exit Sub
        End If
    Next
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top