you need to use regular expressions.
i.e. to validate a uk post code example
string postCodeRegEx =
@"(^((([A-PR-UWYZ])([0-9][0-9A-HJKS-UW]?))|(([A-PR-UWYZ][A-HK-Y])([0-9][0-9ABEHMNPRV-Y]?))\s{0,2}(([0-9])([ABD-HJLNP-UW-Z])([ABD-HJLNP-UW-Z])))|(((GI)(R))\s{0,2}((0)(A)(A)))$)|(^
*$)";
if (System.Text.RegularExpressions.Regex.IsMatch("W1A 1BC",postCodeRegEx)
== false) {
MessageBox.Show("Not a valid post code");
}
Regular expressions look fairly daunting, but like a complex SQL query, if
you do it in parts, they're fairly straight forward.
You need to know about
www.regexlib.com also, otherwise you'll spend ages
reinventing the wheel. Here you can find literally 1,000s of reg
expressions people have already written.
There are also tools for testing them, etc.
HTH
Sam
Dave said:
Hello.
Is there any method to validate if string contains valid IP address?
I also need the method to valideta email address in string.
Thank you.