The information you provide makes it tough to know how to advise. Generally, we can provide better answers and more help when you provide sample code and output (including exact error messages, when relevant. See How do I post a question effectively? (and, perhaps, Writeup Formatting Tips).

So, on to your question

If you're using regexen, to accept, for example, only the digital portion of '$123.45' your might want to "validate" by (grossly oversimplified)

use strict; use warn; my $input = "\$123.45"; if ( $input =~ /\D*(\d{0,3}\.\d{0,2}).*/ ) { my $valid = $1; print $valid; } else { print "not valid\n"; }
prints: 123.45

The regex above (sequentially) looks for (and if found, discards) any leading non-digit character(s), then for 0 to 3 digits, a literal dot and 0 to 2 more digits, capturing the digits and the dot.

For dates, you'd be well-advised to convert the user's input to some standard form, and test that.

And, genericly, you may wish to read about untainting [ Question about untainting data, Untainted done right! (esp tye's reply] and similar nodes found with search or supersearch} because much of what's discussed will be applicable to your data validation needs.

BTW: the notion of ...a variable that is defined as an integer.... may be tripping you up if you're accustomed to a strongly typed language. Perl isn't. OTOH, if you mean that YOU want that $var to be an integer, see the likes of numify....

Update: minor formatting, closed <tt> tag


In reply to Re: perl typecasting by ww
in thread perl typecasting by perl_junkie

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.