SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    checking for decimal places

    hey all i was wondering if any1 no's if there is a way i can check if the value entered in a textbox has decimal places ie 2.03...i would like to no how to catch this ...

    any ideas plz?
    Code is Poetry

  2. #2
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,880
    Mentioned
    48 Post(s)
    Tagged
    0 Thread(s)
    U could try this:

    if (textbox1.Text.IndexOf(".") >= 0)
    {
    //Decimal does exist
    }
    else
    {
    //decimal does not exist
    }

    I hope this helps u. What the IndexOf method does is basically give ut the position of whatever ur looking for in the string beginning at 0 and if does not exist return -1.

    I hope this makes sense

  3. #3
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yep it does thanks
    Code is Poetry

  4. #4
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or some Regular Expressions:
    Code:
     private bool MatchDecimal(string matchString)
     	{
     		Regex reg = new Regex(
     			@"^[-+]?[0-9]\d{0,2}(\.\d{1,2})?%?$",
     			RegexOptions.IgnoreCase
     			| RegexOptions.CultureInvariant
     			| RegexOptions.IgnorePatternWhitespace
     			| RegexOptions.Compiled
     			);
     
     		System.Text.RegularExpressions.Match result = reg.Match(matchString);
     
     		return result.Success;
     	}

  5. #5
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,880
    Mentioned
    48 Post(s)
    Tagged
    0 Thread(s)
    Hey dhtmlgod.

    Ive never quite got Regex. Do u maybe have a link for me to read about how RegularExpressions work and how to write them?

    What is the benefit of it apposed to using other methods?

    Thanks

  6. #6
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Hey NightStalker-DNS

    You can read Regular expression from :-

    http://www.windowsdevcenter.com/pub/...harp_0101.html


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
  •