Hello everyone![]()
I am trying to create a text box which allows the user to enter an IP address only. The user will enter only the numbers and the dots. I have tried using the masked text box, but it does not allow the dot to float
___.___.___.___ this is what it look like, and not all IP addresses are all 3 digits
for example 69.145.230.110
Any help would be greatly appreciated, and mentioned in the read me file!
Here is a regular expression for validating IP addresses:
Just need to send the text in your text box as the parameter for the method and a bool value is returned describing the validity of the IP address. Hope this helps you out.Code:public bool IsValidIP(string addr) { //create our match pattern string pattern = @"^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\. ([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$"; //create our Regular Expression object Regex check = new Regex(pattern); //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; }
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks