/ Published in: C#
Expand |
Embed | Plain Text
public bool IsValidIP(string addr) { //create our match pattern string pattern = @"\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b"; //create our Regular Expression object //boolean variable to hold the status bool valid = false; //check to make sure an ip address was provided if (addr == "") { //no address provided so return false valid = false; } else { //address provided so use the IsMatch Method //of the Regular Expression object valid = check.IsMatch(addr, 0); } //return the results return valid; }
You need to login to post a comment.
