我一直在嘗試驗證正確的座標格式。目前我想保存座標。但是當格式錯誤時,標記不會出現在我的地圖上。使用REGEX驗證正確的座標格式
這是我的一些示例代碼。
String latlon = "3.169054, 101.714108";
String regex_coords = "/\\((\\-?\\d+\\.\\d+), (\\-?\\d+\\.\\d+)\\)/";
Pattern compiledPattern2 = Pattern.compile(regex_coords, Pattern.CASE_INSENSITIVE);
Matcher matcher2 = compiledPattern2.matcher(latlon);
while (matcher2.find()) {
System.out.println("Is Valid Map Coordinate: " + matcher2.group());
}
我希望用戶能夠使用逗號僅保存這種格式「3.169054,101.714108」。
任何人都可以幫助我構建正則表達式來驗證這種格式嗎?
感謝所有
小數位數是否始終爲6? – sp00m 2013-02-20 10:13:14