HomeMonday, June 18, 2018, 15:07:54
2

Preg_Match - PHP Form Validation

Tuesday, February 10, 15, 01:10:37, 3 Yaers Ago Via wain, Hits: 6211
PHP form validation with preg_match
Download source code:
http://phpform.net/download.php?f=pregmatch.zip

index.php

Code:
<?php
if(isset($_POST['submit']))
{
$textvalue = $_POST['textvalue'];
if(preg_match('#[^A-Za-z0-9]#', $textvalue)){
echo "<center><font style=\"font-family:tahoma;\">..letters and numbers only:
<a href=\"javascript:history.go(-1)\">Go Back</a></center>";
Die();
}
if (strlen($textvalue) < 4) {
echo "<center><font style=\"font-family:tahoma;\">..at least 4 characters long:
<a href=\"javascript:history.go(-1)\">Go Back</a></center>";
Die();
}
if (strlen($textvalue) > 40) {
echo "<center><font style=\"font-family:tahoma;\">..max characters: 40
<a href=\"javascript:history.go(-1)\">Go Back</a></center>";
Die();
}
echo "<center><font style=\"font-family:tahoma;\">OK.";
}else{
?>
<form method="post" action="index.php">
<table>
<tr>
<td>
Text:
</td>
<td>
<input name="textvalue" size="60" maxlength="255">
</td>
</tr>
</table>
<table>
<tr>
<td>
<input type="submit" name="submit" value="submit">
</td>
</tr>
</table>
</form>
<?php } ?>

Sign In

Sponsor
Related

Creating a CAPTCHA with PHP with imagecreate

This tutorial will show you how to create a form with Captcha, Requirement(s): PHP Server, GD Graphics Library

Show / Hide Div with CSS

CSS Display and Visibility:The visibility property specifies whether or not an element is visible.

Block Visitors From Specific IP Address

Learn How To Restrict Users From Different IP Addresses.

Advanced Contact Form - PHP Script

Advanced Contact Form with email and form field validation. Features: HTML Output(Response), Captcha Image.

Sitemap

phpForm.net Website Sitemap

MySQL to RSS

Publishing MySQL data in RSS

Site Recommendation

This script will allow your visitors to recommend your site to their friends.

Bookmark Script

Allow your users to easily bookmark your site, by clicking on a link on the page.

php Array

These functions allow you to interact with and manipulate arrays in various ways. Arrays are essential for storing, managing, and operating on sets of variables.

MySQL Inner Join

MySQL Inner Join - Creating Dynamic Webpages Using PHP and MySQL, Requirement(s): PHP Server, MySQL
About Author

wain

Date Registered: Sun, Feb 8, 15
Last Time Online: Sun, Mar 18, 18
So far has created 115 entries.
wain
This author has not yet filled in any details.