Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Regular Expressions

Regular Expressions

Scheduled Pinned Locked Moved C#
regextoolshelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tthellebuyck
    wrote on last edited by
    #1

    Does any one have a decent regular expression for money. I am struggling to get one together, however I need one that matches for something like this: a dollar sign($) 1-4 digits 1-999 two decimal places 1.50 0 and will allow a blank textbox. If anyone has a regex for this or could point me to a utility that would do so, your help is greatly appreciated. thanks

    J S 2 Replies Last reply
    0
    • T tthellebuyck

      Does any one have a decent regular expression for money. I am struggling to get one together, however I need one that matches for something like this: a dollar sign($) 1-4 digits 1-999 two decimal places 1.50 0 and will allow a blank textbox. If anyone has a regex for this or could point me to a utility that would do so, your help is greatly appreciated. thanks

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      Maybe this will get you started: ^\${1}\d{1,4}\.\d{2}$ That will match stuff like $123.45. Note that it may not be perfect; please test it thoroughly before putting it into production. For what it's worth, I don't know much about regular expressions; I simply I generated that using the free Readable Regex[^] library, using the following code:

      string pattern = Pattern.With.AtBeginning.Literal("$").Repeat.Exactly(1)
                      .Digit.Repeat.InRange(1, 4)
                      .Literal(".")
                      .Digit.Repeat.Exactly(2).AtEnd.ToString();

      Tech, life, family, faith: Give me a visit. I'm currently blogging about: The Lord Is So Good The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

      1 Reply Last reply
      0
      • T tthellebuyck

        Does any one have a decent regular expression for money. I am struggling to get one together, however I need one that matches for something like this: a dollar sign($) 1-4 digits 1-999 two decimal places 1.50 0 and will allow a blank textbox. If anyone has a regex for this or could point me to a utility that would do so, your help is greatly appreciated. thanks

        S Offline
        S Offline
        Skippums
        wrote on last edited by
        #3

        @"(^\$([1-9]\d{0,3}|0)\.\d\d$)|(^$)" This SHOULD allow "$1.45" "$0.00" "$50.10" This should NOT allow "$00.00" " $0.00" "0.00" "$0.0" I make no warranties. Jeff

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups