by @kodeazy
How to check A String is a number or not in flutter?
- In this blog we will discuss on how to check if
string
isnumber
ornot
. - To chek if string is number or not we convert it into number.
- After converstion if there is no exception then the given string is number.
-
int.parse
is a function used to convertstring
toint
. -
Below is the example of converting string to number and checking for exception if the given string is number or not.
void main() { try { String s1 = "10A"; int num = int.parse(s1); print('Given String is a number'); } catch (e) { print('Given String is not A Number'); } }
Output:
Given String is not A Number