Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 162
  • Last Modified:

validator

Hey guys i need to know how to validate a textbox so the user enters a domain name or domains follow by a comma.

like this the user must enter

www.ramcon.co.za

or www.ramcon.co.za, www.paintec.co.za

can it be done using regular expression?
0
JCWEBHOST
Asked:
JCWEBHOST
1 Solution
 
strickddCommented:
The easiest way is to create a custom validator and do something like this:

string[] domainSplit = myDomainTextBox.Text.Split(",");

foreach(string domain in domainSplit)
{
   args.IsValid = IsValidDomain(domain);

   if(!args.IsValid)
      return;
}

Open in new window


public static bool IsValidDomain(string Input)

 {

  if (string.IsNullOrEmpty(Input))

  return false;

  Regex TempReg = new Regex(@"^(http|https|ftp)://([a-zA-Z0-9_-]*(?:\.[a-zA-Z0-9_-]*)+):?([0-9]+)?/?");

  return TempReg.IsMatch(Input);

  }

Open in new window

0
 
käµfm³d 👽Commented:
You can try this, but I forewarn you: it is very general.

^(?i)(?:[a-z0-9][a-z0-9-]*(?<!-)\.)+[a-z]{2,6}(?:\s*,\s*(?:[a-z0-9][a-z0-9-]*(?<!-)\.)+[a-z]{2,6})*$

Open in new window

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now