logic like split the given by delimiter "." and proceed accordingly to validate each range ......
Software QA/Tests Interview Questions from Microsoft
(Continued from previous question...)
logic like split the given by delimiter "." and proceed accordingly to validate each range ......
Question:
Had an interv at Microsoft today. Validate IPV4 address is my question..
I have given some logic like split the given by delimiter "." and proceed accordingly to validate each range.
maybe an answer:
public static bool isValidIVP4(string IP)
{
string[] arr = IP.Split('.');
if (arr.Length != 4)
return false;
for (int i = 0; i <= 3; i++)
{//byte.TryParse would handle all cases except when there is a + in the beginning or 0's to the left so we check those cases first:
if (arr[i].Length > 3 || arr[i].Contains('+'))
return false;
byte result;
if (!byte.TryParse(arr[i], out result))
return false;
}
return true;
}
(Continued on next question...)
Other Interview Questions
|