I need to find out if a string is numeric in dart. It needs to return true on any valid number type in dart. So far, my solution is
bool isNumeric(String str) {
try{
var value = double.parse(str);
} on FormatException {
return false;
} finally {
return true;
}
}
Is there a native way to do this? If not, is there a better way to do it?
This can be simpliefied a bit
from double.parse DartDoc
This version accepts also hexadecimal numbers
In Dart 2 this method is deprecated
int.parse(s, onError: (e) => null)
instead, use