Q:

Check text format with preg_match

I'm trying to check some texts with preg_match. 
The text format is numbers separated with , no letters or anything else
just numbers + ","
For example : 10,50,30
Lets say i want to ckeck this :
20,300,60  //ok
50  //ok..yes, ok even if there is no "," because there is no other number after it.
40,,60,60 // not ok..double ","
55,411, //not ok..contain "," at the end
70,800  //ok

I really tried many of things and wasted like 2 hours before i open this Q
Any idea please ?
Thank you.

A:

You can use the regular expression /^\d+(,\d+)*$/:
if (preg_match('/^\d+(,\d+)*$/', $string)) {
    // Matches
} else {
    // Does not match
}

If you want to match fractional numbers, use the following expression:

/^\d+(?:\.\d+)?(,\d+(?:\.\d+)?)*$/

