Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
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

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.
 
Share this answer
 
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.
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]
 
Share this answer
 
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900