Isso não tem sobrecarga de regex
double myNum = 0;
String testVar = "Not A Number";
if (Double.TryParse(testVar, out myNum)) {
// it is a number
} else {
// it is not a number
}
A propósito, todos os tipos de dados padrão, com a notável exceção de GUIDs, oferecem suporte a TryParse.
update
secretwep mostrou que o valor "2345" passará no teste acima como um número. No entanto, se você precisar garantir que todos os caracteres na string sejam dígitos, outra abordagem deve ser adotada.
exemplo 1 :
public Boolean IsNumber(String s) {
Boolean value = true;
foreach(Char c in s.ToCharArray()) {
value = value && Char.IsDigit(c);
}
return value;
}
ou se você quer ser um pouco mais chique
public Boolean IsNumber(String value) {
return value.All(Char.IsDigit);
}
atualização 2 (de @stackonfire para lidar com strings nulas ou vazias)
public Boolean IsNumber(String s) {
Boolean value = true;
if (s == String.Empty || s == null) {
value=false;
} else {
foreach(Char c in s.ToCharArray()) {
value = value && Char.IsDigit(c);
}
} return value;
}