This should work:
preg_match("#^-?\d+(,\d+)?$#", "-1,2", $match);
Matching one or more digits:
"#\d+#"
Optionally matches a comma followed by one or more digits:
"
It is not necessary to match the "-" sign:
"#-?\d+(,\d+)?#"
Allow only this and nothing:
"#^-?\d+(,\d+)?$#"
source
share