|
Use a regular expression. There are several examples of email validation on google - some more accurate than others, so take your time and read around the various implementations (i.e. look for ones that can handle more complex email addresses such as .museum addresses).
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
The best way of doing this is using Regex. Try the below code.
private void txtboxEmailAdd_Validating(object sender, CancelEventArgs e)
{
string pattern = @"^[a-z][a-z|0-9|]*([_][a-z|0-9]+)*
([.][a-z|0-9]+([_][a-z|0-9]+)*)?@[a-z][a-z|0-9|]*\.([a-z][a-z|0-9]*(\.[a-z][a-z|0-9]*)?)$";
System.Text.RegularExpressions.Match match =
Regex.Match(txtboxEmailAdd.Text.Trim(), pattern, RegexOptions.IgnoreCase);
if (match.Success || txtboxEmailAdd.Text == "")
return;
else
MessageBox.Show("Invalid Email Address" + "\r\n" + "Please enter Valid Email", "Invalid Email Error",MessageBoxButtons.OK, MessageBoxIcon.Error);
e.Cancel = false;
}
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Didn't read the question properly!
string s = "Hello@email.com";
if (s.IndexOf("@") <= 0)
{
MessageBox.Show("Not an EMAIL address");
}
This will report on @email.com and email.com, but not on a@email.com
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
This is not a workable solution. What happens if the user enters @me, or bob@bob, or ¬¬¬@¬¬¬?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Agreed it is not the complete solution - it covers the @me case since the indexof returns 0 - but I didn't want to confuse him too much, just answer the question as asked. A regular expression would work better, but I guess the "proper" solution would be to interface to Outlook (or express, or whatever) and check the entered address against his contacts list - ouch!
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Have a look at the RegEx Expression I gave him. It caters for all the validation, checks on the domain etc etc and that there is a valid name@something.com etc. I think I added a check in that there are no spaces in the email address either. I think it is pretty comprehensive in what it checks. Even if I have to say so myself....
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Kwagga wrote: Even if I have to say so myself....
Smartass - your code earns you a perma link as I'm certain to need this sometime in the future! Thanks
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
NO worries mate. Glad I could help 1 person today.....
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
The original RFC regex is (as follows):
(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]) It's not perfect, but is a starting point.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
In datagridview how will I make a validation for the length of text written in cell, eg. mobile no column takes on 10 digits
|
|
|
|
|
|
I am not want in ASP.NET or web page I want to validate in windows application
|
|
|
|
|
Check this one
http://msdn.microsoft.com/en-us/library/ykdxa0bc.aspx[^]
Thank you
Vuyiswa Maseko
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
I have atleast 15 columns but in crystal report the all columns are not legible properly. give me some suggesstions how will I show or print that records. Is there is any option in crystal report of landscape.
thanx in advance
|
|
|
|
|
hEY TRY THIS.
CrystalDecisions.CrystalReports.Engine.ReportDocument r = new CrystalDecisions.CrystalReports.Engine.ReportDocument();<br />
r.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Landscape;
Thanks,
Sun Rays
To get something you must have to try once.
My Articles
|
|
|
|
|
But how will I set the columns
|
|
|
|
|
Hi,
what you want to do ?
You want to display only 10 columns from 15 ?
Explain properly.
Thanks,
Sun Rays
To get something you must have to try once.
My Articles
|
|
|
|
|
No there are 15 columns and I want to show all these columns in landscape form but how will I set the all these columns in crystal report.
|
|
|
|
|
Hi,
do you want this ?
Try[^]
Thanks,
Sun Rays
To get something you must have to try once.
My Articles
|
|
|
|
|
I have very weird problem with the windows command prompts standard input.
When i write regular dos command like cd or dir to the input stream everything goes as expected BUT when i want to execute a GUI app (say notepad) the window doesnt show up until i write some empty lines to the stream?
cmd.StandardInput.WriteLine("notepad");
cmd.StandardInput.Flush();
cmd.StandardInput.WriteLine("blaaaaa");
cmd.StandardInput.WriteLine("blaaaaa");
cmd.StandardInput.WriteLine("blaaaaa");
Please help..this is so weird, even my friend google couldnt help me
|
|
|
|
|
add
cmd.StandardInput.Close();
after
Druuler wrote: cmd.StandardInput.WriteLine("notepad");
cmd.StandardInput.Flush();
*12Code
|
|
|
|
|
Hi thanks for ur answer...but im using asynchronous beginreadline and need to keep cmd alive?
|
|
|
|
|
You only need to close StandardInput, not cmd.
*12Code
|
|
|
|
|
hmm...But cmd exits when i close the input stream and even if it didnt exit how would i go about write to the input stream again?
Could you give an code example maybe?
|
|
|
|
|
Hi all,
I am trying to convert a byte array in to a character array and trying to write the character array in a text file...
The character set till 127 is propetly written.. whereas all the characters which is above 127 is modified as '?' i.e ascii number 63.....
How can i write this to the text file...
the code snippet..
Byte[] encryptedData = myrsa.Encrypt(newdata, false);
Char[] asciiarray = encoding.GetChars(encryptedData);
FileStream fs = File.Open(FilePath,filemode,FileAccess.Write);
sw = new StreamWriter(fs, Encoding.ASCII );
sw.WriteLine(new string (asciiarray));
sw.Close();
The above code writes only ascii characters whose values are less than 127 whereas all other characters are automatically changed to '?'
Googled, but no fruits......
Have a Happy Coding.....
|
|
|
|