#!/usr/bin/perl # check for numbers with punctuation use Strict; # examples for "common-written" numbers foreach my $var ( # should be false '','foo 30','.20','20.',',20','20,', # should be numbers 0,100,'100.23','1,100.23' ) { if (IsANumber($var)) { print "True: $var\n"; } else { print "False: $var\n"; } } sub IsANumber { my $var = $_[0]; if ( # contains digits,commas and 1 period ($var =~ /(^[0-9]{1,}?$)|(\,*?)|(\.{1})/) && # does not contain alpha's, more than 1 period # commas or periods at the beggining and ends of # each line !($var =~ /([a-zA-Z])|(^[\.\,]|[\.\,]$)/) && # is not null ($var ne '') ) { return(1) } else { return(0) } }