Click here to Skip to main content
15,898,374 members
Home / Discussions / C#
   

C#

 
GeneralRe: MenuItem.Shortcut has no Esc key?! Pin
Nick Parker28-Feb-04 4:18
protectorNick Parker28-Feb-04 4:18 
GeneralRe: MenuItem.Shortcut has no Esc key?! Pin
Mazdak28-Feb-04 4:52
Mazdak28-Feb-04 4:52 
GeneralRe: MenuItem.Shortcut has no Esc key?! Pin
profoundwhispers28-Feb-04 5:23
profoundwhispers28-Feb-04 5:23 
GeneralRe: MenuItem.Shortcut has no Esc key?! Pin
Nick Parker28-Feb-04 6:11
protectorNick Parker28-Feb-04 6:11 
GeneralRe: MenuItem.Shortcut has no Esc key?! Pin
Heath Stewart28-Feb-04 4:24
protectorHeath Stewart28-Feb-04 4:24 
GeneralZero Value STRRET Type - GetDisplayNameOf Pin
Tristan Rhodes27-Feb-04 23:34
Tristan Rhodes27-Feb-04 23:34 
GeneralURL Validator Pin
camasmartin27-Feb-04 18:52
camasmartin27-Feb-04 18:52 
GeneralRe: URL Validator Pin
Heath Stewart28-Feb-04 4:16
protectorHeath Stewart28-Feb-04 4:16 
Handle the Validating even on a TextBox (or override OnValidating if deriving from TextBox) and in your validation code, use a Regex instance to check the URL, setting CancelEventArgs.Cancel to true if the regular expression fails.

The regular expression you use is determined by what "URL"s you want to support. The concept of URLs - which is a form of URI - is very vague. Any protocol scheme is allows, though they might not match any protocol handlers. Common schemes are http(s), ftp(s), nntp, news, mailto, gopher, and telnet. Windows adds some (depending on what's installed) like ms-help, its, and some others. You can add them to Mozilla/Netscape, too. And each of these can have slightly different syntax that others don't support.

My advice - unless you want several regular expressions that will slow validation tremendously, just use the Uri class like so:
public class UrlBox : TextBox
{
  // ...
  protected override void OnValidating(CancelEventArgs e)
  {
    try
    {
      new Uri(this.Text);
    }
    catch
    {
      e.Cancel = true;
    }
  }
}
This should handle most variants of URLs.

 

Microsoft MVP, Visual C#
My Articles
GeneralRe: URL Validator Pin
camasmartin28-Feb-04 6:48
camasmartin28-Feb-04 6:48 
GeneralOutlook Bar Problem Pin
BigBlob20227-Feb-04 12:49
BigBlob20227-Feb-04 12:49 
GeneralRe: Outlook Bar Problem Pin
Matthew Hazlett27-Feb-04 13:16
Matthew Hazlett27-Feb-04 13:16 
GeneralRe: Outlook Bar Problem Pin
BigBlob20227-Feb-04 13:24
BigBlob20227-Feb-04 13:24 
GeneralExpert only question...please help me Pin
aleang7227-Feb-04 12:34
aleang7227-Feb-04 12:34 
GeneralRe: Expert only question...please help me Pin
Heath Stewart28-Feb-04 3:59
protectorHeath Stewart28-Feb-04 3:59 
QuestionImpersonation??? Pin
Bill Dean27-Feb-04 12:33
Bill Dean27-Feb-04 12:33 
AnswerRe: Impersonation??? Pin
turbochimp27-Feb-04 17:08
turbochimp27-Feb-04 17:08 
GeneralDataTable problem! Pin
visiontec27-Feb-04 12:03
visiontec27-Feb-04 12:03 
GeneralRe: DataTable problem! Pin
turbochimp27-Feb-04 16:17
turbochimp27-Feb-04 16:17 
Questionhow to use an icon in multiple places Pin
visiontec27-Feb-04 11:43
visiontec27-Feb-04 11:43 
AnswerRe: how to use an icon in multiple places Pin
Heath Stewart28-Feb-04 3:46
protectorHeath Stewart28-Feb-04 3:46 
GeneralIcons Pin
BigBlob20227-Feb-04 10:18
BigBlob20227-Feb-04 10:18 
GeneralRe: Icons Pin
Heath Stewart27-Feb-04 11:27
protectorHeath Stewart27-Feb-04 11:27 
GeneralRe: Icons Pin
BigBlob20227-Feb-04 12:08
BigBlob20227-Feb-04 12:08 
GeneralRe: Icons Pin
Heath Stewart28-Feb-04 3:21
protectorHeath Stewart28-Feb-04 3:21 
Questionwhat is wrong with code?? Pin
SherKar27-Feb-04 10:14
SherKar27-Feb-04 10:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.