|
Hi,
I am searching for the best regex mail pattern with C#.
Thank you,
Cem Louis
|
|
|
|
|
<br />
private Regex emailReg = new Regex(<br />
@"(?<Username>\w[-.\w]*)@(?<Host>[-a-z0-9]+(\.[-a-z0-9]+)*\." +<br />
@"(com|edu|gov|int|mil|net|org|biz|info|name|museum|coop|aero|[a-z][a-z]))",<br />
RegexOptions.IgnoreCase);<br />
Credit goes to http://www.bookpool.com/.x/ocstn6vf4n/sm/0596002890[^]
|
|
|
|
|
I don't recommend hard-coding the TLD (top-level domains). Change that to ([a-z]{1,}) instead and let DNS do its job.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Following that logic, you wouldn't need a Regex at all. Just try to send the email, using any random string as the address, and "let DNS do its job". ([a-z]{1,}) validates lots of invalid email addresses. The last time I checked, only the TLD's, plus 2 letter combinations were valid. Its best to spell this out explicitly in the regex.
|
|
|
|
|
|
So, by your token it's good to hard-code that which changes often. What leppie said is right, and at the very least if you're going to hard-code these values read them from a .config file instead (like from <appSettings> or your own configuration section.
Should one honestly have to fix, recompile, and re-deploy the assemblies that use this each time a new TLD is added?
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
I agree with you, that hard-coding those vales could make it hard to maintain and update the application. Depending on the intended use, there are always tradeoffs. Read from a config file, hard-code them, use your ([a-z]{1,}) method, and probably a few others. The goal of my original post was to give a good starting point for an email regex, and I considered the example from Jeffrey Friedl's book to be pretty good. Thank you for pointing out ways in which it could be improved in practice.
|
|
|
|
|
is there any way to combine my application with MS Equation Editor.
I just tried to give reference to MS Office 10.0 object library to use the equation editor as a com object which inside the Word.but I am failed.
I am lookng for a way to use it in my application. Any tutorials any articles that you can suggest,that it will be helpfull for me.
(visual C# windows application)
Thanks...
|
|
|
|
|
I'm not sure if what I'm wanting to do is possible in C# or not, but I thought I'd pose the question. In C++, we are able to create ActiveX controls and host them in a generic container. The container can read a menu system from a database and populate a tree and have an assigned GUID for the object to construct when each tree node is clicked. Can this phisophy be done in a Windows form .NET application (without ActiveX)? Can I construct a Form or a UserControl by simply reading in the form class name from a database table? I know I can create a builder class that could return a new object for a given piece of text, but that would mean I would have to update this builder class each time a new form were developed. I would like to create a container that never had to be modified...not sure if that is possible.
Ron Ward
|
|
|
|
|
|
Thank you Nick! This is exactly what I needed. I had heard the Reflection term thrown around, but never realized what it was. Being a Visual C++ developer, this term means something very different to me. Thank you again.
|
|
|
|
|
What I am trying to do is to first start a form, which gives the user a choice between starting the application as a server or as a client. When the user has made this choice, the form should terminate. Now I wish to start another form, which provides another user interface. Like this:
static void Main()
{
ServerOrClientForm serverOrClient = new ServerOrClientForm();
Application.Run(serverOrClient);
serverOrClient.InputSelection();
UserInterface ui = new UserInterface();
Application.Run(ui);
// pass information to and from ui
obj = ui.GetInfo();
// ...
ui.SetInfo(obj);
}
The first form works well, but the other one (ui) does not show up at all. What am I doing wrong?
|
|
|
|
|
You are not doing anything wrong, this is a bug in the framework. When Application.Run finishes, a bit is set indicating that the message pump on the thread has shutdown. This bit is sticky, and any subsequent calls to Application.Run see this bit set and immediately terminate.
However, this should workaround your problem:
static void Main()
{
ServerOrClientForm serverOrClient = new ServerOrClientForm();
Application.Run(serverOrClient);
serverOrClient.ShowDialog();
serverOrClient.InputSelection();
UserInterface ui = new UserInterface();
Application.Run(ui);
// pass information to and from ui
obj = ui.GetInfo();
// ...
ui.SetInfo(obj);
}
|
|
|
|
|
Thank you very much for your reply! Regrettably, your solution does not work for me. It still behaves as it did before. I have changed the code into the following:
static void Main()
{
ServerOrClientForm serverOrClient = new ServerOrClientForm();
serverOrClient.ShowDialog();
serverOrClient.InputSelection();
System.Threading.Thread.Sleep(1000);
UserInterface ui = new UserInterface();
ui.ShowDialog();
}
I can clearly see the second form flashing by after the 1 second delay. The first form, however, works fine.
|
|
|
|
|
Please look at the code I had posted. For the "UserInterface" class, do not use ShowDialog(), but rather Application.Run(ui).
|
|
|
|
|
I have tried that, and it did not work either. That's why I tried to use ShowDialog() on both of them.
|
|
|
|
|
What does the function "InputSelection" do?
In a simple test application, this works fine for me:
static void Main()
{
Form1 form1 = new Form1();
form1.ShowDialog();
Application.Run(new Form2());
}
|
|
|
|
|
I found the source to my troubles. When the user presses the OK button in my ServerOrClientForm its clicked handler issued a call to Application.Exit(). Now I call this.Close() instead, which obviously was the better choice. But I am not sure why. Do you know why?
InputSelection is just a way of blocking the caller until ServerOrClientForm has completed its task (merely a busy-wait loop in which I am checking a 'done' flag and if it's not set, put the thread to sleep for a little while). The thing is, I want the form to produce a result and then feed that result to anyone that call theForm.GetResult, and at the same time block the caller until the result is ready. Can you come up with a good solution?
Thank you very much for helping me with my original problem.
|
|
|
|
|
Application.Exit posts the WM_QUIT message which signals to windows to shut down (note, that's "windows", not "Windows"). The application will ultimately exit.
It's typically not a good idea to call Application.Exit .
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Hi,
I use form.Hide() to hide a form, and use form.Show() to bring it back. However, I found that the form's position is changed. How did this happen? I didn't recreate this form, just hide and show again.
How can I keep it as where it was?
Thanks!
|
|
|
|
|
I found this from msdn about "Form.WindowState Property"
Before a form is displayed, the WindowState property is always set to FormWindowState.Normal, regardless of its initial setting. This is reflected in the Height, Left, Top, and Width property settings. If a form is hidden after it has been shown, these properties reflect the previous state until the form is shown again, regardless of any changes made to the WindowState property.
I think this is the reason, my form keeps changing position. But How can I keep it stay where it was?
Thanks in advance.
|
|
|
|
|
You could set some variables to the co-ordinaets of your form when you hide it, then when you show it, re-set the form's position to those variables.
i.e.
Point loc = this.Location;<br />
this.Hide();
//Showing
this.Show();<br />
this.Location = loc;
Not a great solution but would work till you can get a better one.
Kev
Robert E. Lee's Truce
Judgement comes from experience; experience comes from poor judgement.
|
|
|
|
|
|
can anyone tell me ho do i play and stop either a wma ...mp3...wav file....without using the media player ocx...
|
|
|
|
|
You might wanna try looking into DirectX 9 SDK.
The Microsoft.DirectX.DirectSound namespace (I think this is correct) has what you need.
Try searching MSDN for documentation.
Kev
Robert E. Lee's Truce
Judgement comes from experience; experience comes from poor judgement.
|
|
|
|