Posted on 2011-10-12
Last Modified: 2012-05-12
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


can it be done using regular expression?
Question by:JCWEBHOST
    LVL 28

    Accepted Solution

    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);

    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

    LVL 74

    Expert Comment

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


    Open in new window


    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now