Skip to content

Instantly share code, notes, and snippets.

@hagbarddenstore
Created October 22, 2013 15:47
Show Gist options
  • Save hagbarddenstore/7103070 to your computer and use it in GitHub Desktop.
Save hagbarddenstore/7103070 to your computer and use it in GitHub Desktop.
void Main()
{
var a = "1234";
var b = "abcd";
Console.WriteLine(IsValid(a)); // True
Console.WriteLine(IsValid(b)); // False
}
bool IsValid(string s)
{
foreach (var c in s)
{
switch (c)
{
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '0':
case '.':
case '-':
continue;
default:
return false;
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment