An array of functions to use in checking user input to HTML forms : text, firstName, middleNameOrInit, lastName, email, web, digits, decimal, hex, genNum, USD, BPS, Euro, USphone, USzip
<?php
/*
* (c) 2006, D.E. Silvia, All rights reserved.
* This code is available for use for non-commercial purposes.
* Free to distribute as long as this copyright information remains intact.
* No modification is authorized. Please, refer bugs/enhancements to
* dsilvia@mchsi.com
*
*/
/*
*
* Array of functions to validate HTML form input. Input types are:
*
* text Any text
* firstName Person's first name
* middleNameOrInit Person's middle name or initial
* lastName Person's last name
* email Person's email address
* web Fully qualified http URL
* digits Input is digits (integer) only
* decimal Input is decimal with possible decimal point
* hex Input is hexidecimal
* genNum Input is a general number
* USD US Dollars with possible currency sign and decimal places
* BPS British Pounds Sterling with possible currency sign and decimal places
* Euro Ruro Dollars with possible currency sign and decimal places
* USphone US fully qualified phone number
* USzip US postal zip code
*
* Functions check to see that there is input, then that the input
* is of a valid form.
*
* Calling syntax:
*
* $isValid=$formValidator['text']($userText);
* if($isValid)
* {
* // appropriate processing
* }
*/
// validate there is input
$formValidator['text']='validText';
// validate input is alphabetic or dot
$formValidator['firstName']='validFirstName';
// validate input is alphabetic or dot
$formValidator['middleNameOrInit']='validMiddleNameOrInit';
// validate input is alphabetic or dot, space, or hyphen
$formValidator['lastName']='validLastName';
// validate input is 2 fields separated by 'at sign' (@) and
// fields are alphanumeric, underscore, dot, or hyphen
$formValidator['email']='validEmail';
// validate input begins with http (case insensitive) followed by a
// colon and 2 slashes with alphnumeric, underscore, dot, hyphen and
// possibly followed by an ending slash
$formValidator['web']='validWeb';
// validate input is integer
$formValidator['digits']='validDigits';
// validate input is float
$formValidator['decimal']='validDecimal';
// validate input is hexidecimal
$formValidator['hex']='validHex';
// validate input is all digits. has additional argument of exact length
$formValidator['genNum']='validGenNum';
// validate input is in US dollar format.
// possible leading '$' and possible trailing 2 place decimal.
$formValidator['USD']='validUSD';
// validate input is in British Pounds Steling format.
// possible leading '£' and possible trailing 2 place decimal.
$formValidator['BPS']='validBPS';
// validate input is in European Union Euro format.
// possible leading '€' and possible trailing 2 place decimal.
$formValidator['Euro']='validEuro';
// validate input is 10 decimal digits
$formValidator['USphone']='validUSphone';
// validate input is 5 decimal digits, possibly followed by '-' and 4 decimal digits
$formValidator['USzip']='validUSzip';
?>