I have two regexes took from here: https://stackoverflow.com/a/26119160/2829150 It should correctly validate both latitude and longitude. Nevertheless something is wrong, and for valid coordinates it gives me false.
Example (valid) coordinates which is till got as it is not valid according to methods regex.
Lat: 53.0102721
Lon: 18.6048094
Code:
public static bool IsValidLatitude(string latitude)
{
var reg = new Regex(@"^(\+|-)?((\d((\.)|\.\d{1,6})?)|(0*?[0-8]\d((\.)|\.\d{1,6})?)|(0*?90((\.)|\.0{1,6})?))$");
return reg.IsMatch(latitude);
}
public static bool IsValidLongitude(string longtitude)
{
var reg = new Regex(@"^(\+|-)?((\d((\.)|\.\d{1,6})?)|(0*?\d\d((\.)|\.\d{1,6})?)|(0*?1[0-7]\d((\.)|\.\d{1,6})?)|(0*?180((\.)|\.0{1,6})?))$");
return reg.IsMatch(longtitude);
}
Note that: it don't need to be regex. It can be whatever else keeping in mind to check whether dot (.) was used no matter to what pc settings for separator is set up. I am open on any other proposition.