I have found methods to stop it being typed in, but this doesn't prevent copy/paste methods.
Does anyone know how to allow it in?
So I can enter [for example]
without it being rejected.David's name isn't John
Moderator: General Moderators
without it being rejected.David's name isn't John
You have to handle this before you store the data. Commas and dollar signs etc. are NOT numbers, so if you try to store something with such characters embedded as a number (integer or floating point), it will stop when it hits a non-numeric character. Your script needs to validate every entry before storing it, anyway. Then you can either fix it (like removing any commas) or notify the user that an entry is invalid.simonmlewis wrote:Mmmm this is strange.
It works when the field is "TEXT", but if someone enter a number, ie 4,999.99 into an INT field, it just enters the 4.
I'm assuming the answer is to have a 'value' field to be a TEXT field too, but I need to do mathematic with the contents of that field, and don't know if it works when the field type is TEXT.
Any suggestions?
People are likely to enter 4,999.99 rather than just 4999.99.
There are several useful functions, but the most flexible are surely the regex (regular expressions) functions. Read these:simonmlewis wrote:I know how to check if a variable is empty, or has a particular word, but how do you ask if a variable contents "contains" something?
Pseudo:
if ($price does not contain £ OR , OR'....), { do the job}.
Code: Select all
$pricetest = $_POST['price'];
// create a string
$string = $pricetest;
// match our pattern containing a special sequence
preg_match_all("/[\d]/", $string, $matches);
// loop through the matches with foreach
foreach($matches[0] as $price)
{
echo $price;
}Any ideas?remove anything but numbers, then insert a fullstop third in from the left.
Code: Select all
$price = $_POST['price'];
$price = eregi_replace(",","",$price);
$price = eregi_replace("£","",$price);
$price = eregi_replace("$","",$price);
$price = eregi_replace("€","",$price);1999.00
Code: Select all
$var = $_POST['price'];
$price = sprintf('%0.2f', preg_replace('/[^0-9.]/', '', $var));Code: Select all
<?php
$var = $_POST['price'];;
$clean = sprintf('%0.2f', preg_replace('/[^0-9.]/', '', $var));
echo $clean;
?>