System.Net.HttpWebRequest.HttpWebRequest.CheckValidHost C# (CSharp) Method

CheckValidHost() static private method

static private CheckValidHost ( string val ) : bool
val string
return bool
		static bool CheckValidHost (string val)
		{
			if (val == null)
				throw new ArgumentNullException ("value");

			if (val.Length == 0)
				return false;

			if (val [0] == '.')
				return false;

			string [] parts = val.Split ('.');
			int l = parts.Length;
			string [] last = parts [l - 1].Split (colon, 2);
			if (last.Length == 2) {
				parts [l - 1] = last [0];
				ushort port;
				if (!UInt16.TryParse (parts [1], out port))
					return false;
			}

			// MS does not enforce a max. 255 length
			// MS does not complain about a leading dash or all numbers...
			return true;
		}