开发者

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 ,-]+$
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜