Click here to Skip to main content
14,302,017 members
Rate this:
Please Sign up or sign in to vote.
See more:
hey i want to know how to validate textbox that it only accepts email address

thanks :d
Posted
Comments
Sergey Alexandrovich Kryukov 22-Feb-12 16:44pm
   
Not a question. If you want it, validate it. What's the problem?
--SA
Rate this:
Please Sign up or sign in to vote.

Solution 1

You'll probably want to look into Regular Expressions[^] (and here's a more C# specific article[^] on how to use them). Fortunately for you, there should be plenty of existing patterns for checking email addresses, as it's a very common use for them.
   
Comments
newbie011292 21-Feb-12 16:21pm
   
you have some code? but thanks anyway :D
lewax00 21-Feb-12 16:29pm
   
The second link has some code you should be able to adapt. I doubt anyone here is going to write if completely for you. Google "email address regular expression" or something similar if you need help on the pattern, as I said it's so common you're bound to find one already made.
Rate this:
Please Sign up or sign in to vote.

Solution 3

Expresso is good free tool to test regular expressions and it can be downloaded from

http://www.ultrapico.com/Expresso.htm[^]

If you are using Windows forms, then in Validating event of the TextBox, test the TextBox.Text property using Regex.IsMatch method for the pattern of email. If it fails then set e.Cancel = true else set e.Cancel = false

If your problem is solved you may accept and vote the solution, otherwise please post your queries

PES

[edit]Spelling mistake in It it fails corrected to If it fails[/edit]
   
v2
Comments
Sergey Alexandrovich Kryukov 22-Feb-12 16:43pm
   
This is a useful advice, a 5.
--SA
ProEnggSoft 22-Feb-12 18:42pm
   
Thank you SAKryukov.
PES

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100