note 102088 added to function.preg-match
| From: | Frank at osu1 dot php dot net | Date: | Wed, 26 Jan 2011 20:12:44 +0000 |
| Subject: | note 102088 added to function.preg-match | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-176355@lists.php.net to get a copy of this message | ||
If someone is from a country that accepts decimal numbers in format 9.00 and 9,00 (point or comma),
number validation would be like that:
<?php
$number_check = "9,99";
if (preg_match( '/^[\-+]?[0-9]*\.*\,?[0-9]+$/', $number_check)) {
return TRUE;
}
?>
However, if the number will be written in the database, most probably this comma needs to be
replaced with a dot.
This can be done with use of str_replace, i.e :
<?php
$number_database = str_replace("," , "." , $number_check);
?>
----
Server IP: 69.147.83.197
Probable Submitter: 89.201.145.12
----
Manual Page -- http://www.php.net/manual/en/function.preg-match.php
Edit -- https://master.php.net/note/edit/102088
Del: integrated -- https://master.php.net/note/delete/102088/integrated
Del: useless -- https://master.php.net/note/delete/102088/useless
Del: bad code -- https://master.php.net/note/delete/102088/bad+code
Del: spam -- https://master.php.net/note/delete/102088/spam
Del: non-english -- https://master.php.net/note/delete/102088/non-english
Del: in docs -- https://master.php.net/note/delete/102088/in+docs
Del: other reasons-- https://master.php.net/note/delete/102088
Reject -- https://master.php.net/note/reject/102088
Search -- https://master.php.net/manage/user-notes.php