to enter a phone no - Programmers Heaven

Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

to enter a phone no

neenasasidharaneenasasidhara Posts: 2Member
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

  • JoeMcJoeMc Posts: 55Member
    : 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.