Perl 6

Moderators: Jonathan
Number of threads: 11
Number of posts: 19

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
to enter a phone no Posted by neenasasidhara on 26 May 2007 at 3:02 AM
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
Report
Re: to enter a phone no Posted by JoeMc on 3 Jul 2007 at 12:30 PM
: 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:

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!\n";
    }
    $LOGOUT->close();
}


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

if (! ($passed_var =~ /\d/) ) {

    print "passed_var is not a number!\n";
    # 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.\n";
}


Hope that helps.
Regards,
JoeMc




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.