bool isNumeric(String s) {
if (s == null) {
return false;
}
return double.tryParse(s) != null;
}
//From coflutter.com
bool isNumericUsingRegularExpression(String string) {
final numericRegex =
RegExp(r'^-?(([0-9]*)|(([0-9]*).([0-9]*)))$');
return numericRegex.hasMatch(string);
}
void main() {
var stringArr = ["Hello world", "Hello1 World", "H23llo", "H00Elo", "World"];
for (var i = 0; i < stringArr.length; i++) {
bool found = stringArr[i].contains(new RegExp(r'[0-9]'));
print(stringArr[i] + " -> " + found.toString());
}
}