to enter a phone no

hi
i want to get a errror message if i enter a string value instead of integer in a text field
can anybody plz help me

Comments

  • : hi
    : i want to get a errror message if i enter a string value instead
    : of integer in a text field
    : can anybody plz help me
    :
    Here's a couple different approaches:

    [code][color=Blue]sub check_area_code {
    my $file = "/path/error.log"
    my $LOGOUT = FileHandle->new(">> ${file}") or die ("Can not write to ${file}: $!");
    my $len = do { length $area_code };

    if ( $len == 3 && ( $area_code =~ /[0-9][0-9][0-9]/ ) && (! ($area_code =~ /911/ )) ) {
    # do something...
    } else {
    print $LOGOUT "error invalid area code in phone number!
    ";
    }
    $LOGOUT->close();
    }[/color][/code]

    OR Have you tried setting up a condition like such and send in one char at a time:

    [code][color=Blue]if (! ($passed_var =~ /d/) ) {

    print "passed_var is not a number!
    ";
    # you could either print this to an error log file or to STDERR.
    # not sure what you wanted from here on. ?
    # or maybe set a variable to 0 and use it like a flag of some sorts.

    } else {

    print "All is ok, we have a number.
    ";
    }[/color][/code]

    Hope that helps. :-)
    Regards,
    JoeMc

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion