Think about Loose Coupling | |
PerlMonks |
Re: Verifying number inputby dvergin (Monsignor) |
on Dec 08, 2001 at 09:00 UTC ( [id://130383]=note: print w/replies, xml ) | Need Help?? |
A few comments. First, you appear to be using "use strict;".
That's a good sign. It will save you a lot of grief
in the long run.
You are using some indenting. But it is deceptive -- the indenting doesn't correspond to what you are doing. And several aspects of your logic would be much clearer with the help of some indenting that made the flow of your code clear. Finally, and in answer to your question, here is a slightly re-worked version of your code that does what you want. Note that I also put in a feedback line for the 0-99.99 test that you do. Your regex tested to see if there was anything that was not a digit. This approach /^[\d.]+$/ tests to see if between the beginning and the end of the string there are one or more characters that can only be digits or a period. If any other character appears in the string, the test fails. There are other ways to attack this, but I have stayed fairly close to your logic. Hope this helps. David Update: coolmichael is right, of course. A revised regex might be: /^\d+(\.\d+)?$/
------------------------------------------------------------
In Section
Seekers of Perl Wisdom
|
|