Closed Thread
Results 1 to 2 of 2

Thread: Numeric Text box coding

  1. #1
    MiPaul is offline Newbie
    Join Date
    Feb 2010
    Posts
    1
    Rep Power
    0

    Numeric Text box coding

    Hello everyone

    I am trying to create a text box which allows the user to enter an IP address only. The user will enter only the numbers and the dots. I have tried using the masked text box, but it does not allow the dot to float

    ___.___.___.___ this is what it look like, and not all IP addresses are all 3 digits

    for example 69.145.230.110

    Any help would be greatly appreciated, and mentioned in the read me file!

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    gaylo565's Avatar
    gaylo565 is offline Programming Professional
    Join Date
    May 2007
    Location
    flagstaff, az
    Posts
    268
    Rep Power
    21

    Re: Numeric Text box coding

    Here is a regular expression for validating IP addresses:
    Code:
    public bool IsValidIP(string addr)
    {
        //create our match pattern
        string pattern = @"^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.
        ([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$";
        //create our Regular Expression object
        Regex check = new Regex(pattern);
        //boolean variable to hold the status
        bool valid = false;
        //check to make sure an ip address was provided
        if (addr == "")
        {
            //no address provided so return false
            valid = false;
        }
        else
        {
            //address provided so use the IsMatch Method
            //of the Regular Expression object
            valid = check.IsMatch(addr, 0);
        }
        //return the results
        return valid;
    }
    Just need to send the text in your text box as the parameter for the method and a bool value is returned describing the validity of the IP address. Hope this helps you out.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 10-10-2010, 11:06 AM
  2. Replies: 0
    Last Post: 07-02-2010, 01:43 PM
  3. [x86 ASM] alpha-numeric keys
    By Sysop_fb in forum Classes and Code Snippets
    Replies: 0
    Last Post: 02-12-2010, 07:29 AM
  4. please help with input data and numeric up/down!
    By tynkir in forum C# Programming
    Replies: 3
    Last Post: 03-25-2009, 08:45 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts