I need php regular expression for numeric value including "-" and ","
In php is_numeri开发者_运维知识库c function not allow '-' and ','.
This one should work:
preg_match("#^-?\d+(,\d+)?$#", "-1,2", $match);
Matching one or more digits:
"#\d+#"
Optionally match a comma followed by one or more digits:
"#\d+(,\d+)?#
Optionally match a "-" sign:
"#-?\d+(,\d+)?#"
Allow only this and nothing else:
"#^-?\d+(,\d+)?$#"
is_numeric()
does allow negative numbers. I think the problem is just with the comma.
is_numeric( str_replace( ',', '.', $number ) );
See also Converting a number with comma as decimal point to float
try with this expression
^[0-9 ,-]+$
精彩评论