I have a script that I want to use if() to check adn see if the $string has only numbers and commas.
E.g:
if (isnumber($number)) {
echo "it is a number";
} else {
echo "it is not jsut number";
}
Numbers and commas only
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
since you didn't specify specifics as to format...
Code: Select all
^[0-9,]+$Thanks feyd.
I put it into this:
Is that the best way to do it?
I put it into this:
Code: Select all
<?php
$what = "2,d67";
if (preg_match("/^[0-9,]+$/is", $what, $match )) {
echo "yep";
} else {
echo "nope";
}
?>I usually do it like:
Code: Select all
if ($what == strval(floatval($what))
{
//
}