The following is the source code:
<html><head><style> . Error{color:#FF0000;}
Style
>
Head
><body>
//define variables and set to empty values$NAMEERR=$EMAILERR=$GENDERERR=$WEBSITEERR="";$name=$email=$gender=$comment=$website="";if($_server["Request_method"] =="POST"){if(Empty($_post["Name"])) {$NAMEERR="Name is required";}Else{$name= Test_input ($_post["Name"]);//Check if name only contains letters and whitespaceif(!preg_match ("/^[a-za-z]*$/",$name)) {$NAMEERR="Only letters and white space allowed"; } }if(Empty($_post["Email"])) {$EMAILERR="Email is required";}Else{$email= Test_input ($_post["Email"]);//Check if e-mail address syntax is validif(!preg_match ("/([\w\-]+\@[\w\-]+\.[ \w\-]+)/",$email)) {$EMAILERR="Invalid email format"; } }if(Empty($_post["website"])) {$website="";}Else{$website= Test_input ($_post["website"]);//Check if URL address syntax is valid (this regular expression also allows dashes in the URL)if(!preg_match ("/\b (?:(?: https?| FTP): \/\/|www\.) [-a-z0-9+&@#\/%?=~_|!:,.;] *[-a-z0-9+&@#\/%=~_|] /I ",$website)) {$WEBSITEERR="Invalid URL"; } }if(Empty($_post["comment"])) {$comment="";}Else{$comment= Test_input ($_post["comment"]);}if(Empty($_post["Gender"])) {$GENDERERR="Gender is required";}Else{$gender= Test_input ($_post["Gender"]);}} functiontest_input($data){$data= Trim ($data);$data= Stripslashes ($data);$data= Htmlspecialchars ($data);return$data;}?><h2>PHP Form Validation Example
H2
><p><spanclass="error">* Required field.
span
>
P
><formMethod="POST"Action="
php_self "]);? >"> Name:<inputtype="text"name="name"><spanclass="error">*
echo$nameErr;? >
span
><br><br>E-Mail:<inputtype="text"name="Email"><spanclass="error">*
echo$emailErr;? >
span
><br><br>Website:<inputtype="text"name="website"><spanclass="error">
echo$websiteErr;? >
span
><br><br>Comment:<textareaname="comment"rows="5"cols= "> "
textarea
><br><br>Gender:<inputtype="Radio"name="Gender"value ="female">Female<inputtype="Radio"name="Gender"value ="Male">Male<spanclass="error">*
echo$genderErr;? >
span
><br><br><inputtype="Submit"name="Submit"value ="Submit">
Form
>
Echo "Your Input:
"; Echo $name; Echo "
"; Echo $email; Echo "
"; Echo $website; Echo "
"; Echo $comment; Echo "
"; Echo $gender; ?>
body
>
HTML
>
The above describes PHP-verify Name, e-mail, and URL, including the aspects of the content, want to be interested in the PHP tutorial friends helpful.