开发者

query check if its latitude or just text on map

On search, I want to check if query is latitude and longitude or just text search with PHP.

$query = '-122.0307642, 37.3316930';

latitude and 开发者_运维知识库longitude can have '-' in them also.

What preg_match pattern it will be for this?


The following regex will match two numbers (with or without a negative sign, separated by a comma) of the format a.b where a and b are digit-sequences of minimum length one.

(-?\d+\.\d+)\s*,\s*(-?\d+\.\d+)


Something like this:

(-?\d+(?:\.\d+)?)(?:,\s*|\s+)(-?\d+(?:\.\d+)?)

This will net you two matches, which you can then cast to floats and check against lat/lng bounds.

This will also allow the two numbers to be separated by space. If you want to only allow a comma, use:

(-?\d+(?:\.\d+)?),\s*(-?\d+(?:\.\d+)?)
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜