masking the text in textbox c#2003
-
I want to mask the text for identifying the corrent syntax of IP address example 10.179.10.28 // is correct 10.567.7889.7. // is incorrect how to identify the incorrect one.
vivek
Hello, A quick validation would be to split the string (string.Split('.')) and chek if the elements of the array (return value of Split method is string[]) are not longer than 3 characters. Additionaly you could also check the Length of the string[]. Hope it helps! All the best, Martin
-
I want to mask the text for identifying the corrent syntax of IP address example 10.179.10.28 // is correct 10.567.7889.7. // is incorrect how to identify the incorrect one.
vivek
Hello again! Here I found a very nice solution with regex!
public bool IsValidIPAddress(string ipAddr) {
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}$";
Regex reg = new Regex(pattern, RegexOptions.Singleline | RegexOptions.ExplicitCapture);
return reg.IsMatch(ipAddr);
}http://blog.devstone.com/Aaron/archive/2006/03/29/222.aspx[^] All the best, Martin