Additude has asked for the wisdom of the Perl Monks concerning the following question:
Criteria is:
1. Value must be followed by 2 digits after the period.
2. Value must have at least one digit in front of the period.
3. either digit sequences on either side of the period can only have digits. No non-word characters like white space, $#@!%&*()-_+=~`:;"'}{]|\/?.(more than one period)<>, are allowed.
What I need to end up with is that no matter what the user puts in the form field, it will only accept *X.XX where *X. is any dollar amount and .XX is any cents amount.
$50.00 or 50.0.0 or 50 will not work, it has to be 50.00.
50 is just an example, I need to work with any dollar.cents amount.
This is what I have done so far, but I can't get it to work all the way.
I feel I am so close but something is just not right and I can't figure it out.$Amount =~ /-?(\d+)\.?(\d+)/; $intergerpart = $1; $decimalpart = $2; if ($lengthdecimal gt 2 || $Amount =~ /[^0-9]\.?[^0-9]/) { display_output($templatefile,); #HTML error file print <<EOF; #Continues Processing }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex Dollar Amounts
by japhy (Canon) on Oct 19, 2001 at 07:16 UTC | |
by Additude (Initiate) on Oct 19, 2001 at 16:04 UTC | |
|
Re: Regex Dollar Amounts
by andreychek (Parson) on Oct 19, 2001 at 07:22 UTC | |
by Additude (Initiate) on Oct 19, 2001 at 15:13 UTC | |
by Additude (Initiate) on Oct 19, 2001 at 15:51 UTC | |
|
perldoc -q redux
by Fletch (Bishop) on Oct 19, 2001 at 07:45 UTC |