Write a simple regular expression to match an IP address,
e-mail address, city-state-zipcode combination.

Answer Posted / jayakumar.b

sub validate_ip {

my $ip = shift;

if ( $ip =~ m/^([1-9]|1[0-9]{1,2}|2[0-4]\d|25[0-5])(\.([0-9]|1[0-9]{1,2}|2[0-4]\d|25[0-5])){3}$/ ) {
return 0;
} else {
return 1;
}
}

validate_ip("127.0.0.1");

Is This Answer Correct ?    4 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why Perl aliases are considered to be faster than references?

622


what are steps to do to lock the sony ericsson mobile with password?

1884


What does cgi program store?

613


How to print escaping characters inside a string in perl?

604


What are the various uses of perl?

605






How to prevent file truncation in perl?

585


what is the main function of fork() in cgi programming?

638


Give an example of the -i and 0s option usage.

550


How does polymorphism work in perl? Give an example.

540


How will you open a file in a write-only mode in perl?

580


What is perl I used for?

622


What are the various flags/arguments that can be used while executing a perl program?

535


What does the q{ } operator do?

593


Give an example of using the -n and -p option.

631


Explain what is the scalar data and scalar variables in Perl?

635