I have been frying my brain on a regex that tests a users input to an HTML Form of a dollar amount, like $50.00 and will check it for anything other than digits. What I need to end up with is allowing a good digit sequence to pass and sending a bad digit sequence to an error page telling the user to re-input the values.
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.
$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
}
I feel I am so close but something is just not right and I can't figure it out.
I hope one of you wizards can help out.
TIA!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.