using System;
namespace Sp.Common
{
public class ValidatorHelper
{
/// <summary>
/// 验证经度
/// </summary>
/// <param name="input">待验证的字符串</param>
/// <returns>是否匹配</returns>
public static bool IsLongitude(string input)
{
////范围为-180~180,小数位数必须是1到5位
//string pattern = @"^[-+]?((1[0-7]d{1}|0?d{1,2}).d{1,5}|180.0{1,5})$";
//return IsMatch(input, pattern);
float lon;
if (float.TryParse(input, out lon) && lon >= -180 && lon <= 180)
return true;
else
return false;
}
/// <summary>
/// 验证纬度
/// </summary>
/// <param name="input">待验证的字符串</param>
/// <returns>是否匹配</returns>
public static bool IsLatitude(string input)
{
////范围为-90~90,小数位数必须是1到5位
//string pattern = @"^[-+]?([0-8]?d{1}.d{1,5}|90.0{1,5})$";
//return IsMatch(input, pattern);
float lat;
if (float.TryParse(input, out lat) && lat >= -90 && lat <= 90)
return true;
else
return false;
}
}
}