Tuesday, September 8, 2009

IP address regex

///
/// Validate that String is an IP address.
/// Between 0.0.0.0 and 255.255.255.255
///

protected Regex regIP = new Regex(
@"(?2[0-4]\d|25[0-5]|[01]?\d\d?)\.(?2[0-4]\d|25"
+ @"[0-5]|[01]?\d\d?)\.(?2[0-4]\d|25[0-5]|[01]?\d\d?)\.(?"
+ @"2[0-4]\d|25[0-5]|[01]?\d\d?)",
RegexOptions.IgnoreCase
| RegexOptions.CultureInvariant
| RegexOptions.IgnorePatternWhitespace
| RegexOptions.Compiled
);

No comments: