Code: Select all
<?php
function getIt($value){
if($_GET[$value]){
return $_GET[$value];
}else{
return "";
}
}?>
<input type="text" name="price" value="<?php echo getIt("price")?>">
<input type="text" name="title" value="<?php echo getIt("title")?>">I want to validate my input using preg_match, (I'm assuming this would be the easiest and most secure method).
How can I modify my script so that preg_match:
ONLY accepts numbers, dollar signs and periods from:
<input type="text" name="price" value="<?php echo getIt("price")?>">
and ONLY accepts values containing letters and numbers from:
<input type="text" name="title" value="<?php echo getIt("title")?>">
I want to use somthing like this:
if (preg_match('/^\d{5}(-\d{4})?$/',$_GET['zip'])) {
$zip = $_GET['zip'];
} else {
die('Invalid ZIP Code format');
}
Thanks!