Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how do i be specific of gmail or yahoo email id only
ends with gmail.com or yahoo.com Or yahoo.co.in

VB
Public Function ValidEmail(ByVal Email As String, ByRef invalid As String, ByRef textbox As TextBox) As String


        Dim pattern As String = "([0-9a-zA-Z\-_]*@)gmail.com" ????


        Dim match As System.Text.RegularExpressions.Match = Regex.Match(Email.Trim(), pattern, RegexOptions.IgnoreCase)

        If (match.Success) Then
            'MsgBox("Valid email id")
            Return Email
        Else
            invalid = invalid & Email & Environment.NewLine
  'MsgBox("Invalid email id")
        End If
        Return Nothing

    End Function


What I have tried:

how do i be specific of gmail or yahoo email id only
ends with gmail.com or yahoo.com Or yahoo.co.in
Posted
Updated 18-Feb-17 8:49am

 
Share this answer
 
In a case like this, it would make much more sense to split the string on '@' character. Then validate that first part is not empty and that second part is one of the supported on.

Or if Regex class is used, then I would capture the domain part and then check it against predefined list.

Read the documentation for more information: Regex Class (System.Text.RegularExpressions)[^]
 
Share this answer
 
Comments
Member 10974007 18-Feb-17 12:01pm    
interesting can you plz right down the codes for me ---->>>?
and do you have any pdf or any other reference
Philippe Mori 18-Feb-17 12:09pm    
Use Google and type string split. You will find a lot of information.
Try this:
.+@gmail.com|.+@yahoo.com|.+@yahoo.co.in
 
Share this answer
 
A few link to help you build and debug RegEx by yourself.

Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx:
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900