SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: Regex help

Threaded View

  1. #1
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Regex help

    I'm making a regex to validate money data, and these are the rules I want: (X will represent numbers)

    $ must be at front
    .XX -OR- .X is optional for end
    . at end NOT valid
    1-3 digits left of decimal
    infite combinations of XXX, where needed

    Examples of valid formats
    $xx,xxx.xx
    $xxx,xxx,xxx,xxx
    $x,xxx,xxx.x
    $x.xx

    Examples of invalid formats:
    $xxxxx
    xx,xxx.xx
    $xx,xxx.
    $xxx,xxx.xxx

    Here is what I've got so far, but I know it doesn't work...
    Code:
    moneyReg = "^\\$([0-9]{1,3}[,]{1})*([0-9]{1-3})+(\\.[0-9]{1,2})?$";
    I've had several iterations that have had some success, but not total. This is where I am now, and it breaks pretty much on everything...my brain is too tired to backtrack.

    Thanks in advance!
    Last edited by beetle; Jul 23, 2002 at 10:12.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev





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
  •