-2

I'm developing a module where I need to take input from a user one of each is users email. In order to filter out a wrong input I want to check if a corresponding checkbox has an @ sign.

Does anyone knows how can I check it using vb.net ?

Satinder singh
  • 10,100
  • 16
  • 60
  • 102
meks
  • 777
  • 3
  • 12
  • 23
  • 7
    use the `String.Contains("@")` http://msdn.microsoft.com/en-us/library/dy85x1sa.aspx on the control: `TextBox.Text.Contains("@")` – Aristos May 04 '13 at 09:27
  • 3
    I think is better to check if is a "valid" email address like: http://stackoverflow.com/questions/1331084/how-do-i-validate-email-address-formatting-with-the-net-framework – Irvin Dominin May 04 '13 at 09:30

2 Answers2

2

Aside the main question to check if a string contains the @ character and considering that you are getting your string from a user input, in your case I think is better to check if the user entered a valid mail address.

To do so there are some solutions all reported in this other SO question How do I validate email address formatting with the .NET Framework?

Community
  • 1
  • 1
Irvin Dominin
  • 30,819
  • 9
  • 77
  • 111
1

In ASP.NET you can use RegularExpressionValidator for this.

<asp:RegularExpressionValidator ID="regexEmailValid" runat="server" 
      ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" 
      ControlToValidate="tbEmail" 
      ErrorMessage="Invalid Email Format">
</asp:RegularExpressionValidator>
Damith
  • 62,401
  • 13
  • 102
  • 153