Mega Code Archive

 
Categories / Perl / CGI
 

Process form with regular expression

<html> <head> <title>form page</title> </head> <body> <p>here's my test form</p> <form method = "post" action = "your.pl"> <p>First name:  <input name = "firstName" type = "text" size = "20"></p> <p>Last name:  <input name = "lastName" type = "text" size = "20"></p> <p>Phone number:  <input name = "phone" type = "text" size = "20"></p> <p>Date (MM/DD/YY):  <input name = "date" type = "text" size = "20"></p> <p>Time (HH:MM:SS):  <input name = "time" type = "text" size = "20"></p> <input type = "submit" value = "submit"> <input type = "reset" value = "reset"> </form> </body> </html> #your.pl #!/usr/bin/perl use strict; use warnings; use CGI ':standard'; my $firstName = param( "firstName" ); my $lastName = param( "lastName" ); my $phone = param( "phone" ); my $date = param( "date" ); my $time = param( "time" ); print header(); print start_html( -title => "form page" ); if ( $time =~ m#^(1[012]|[1-9]):([0-5]\d):([0-5]\d)$# ) {    print "<p>The time is $1 : $2 : $3.</p>"; } print end_html();