by @kodeazy

How to check A String is a number or not in flutter?

Home » flutter » How to check A String is a number or not in flutter?
  • In this blog we will discuss on how to check if string is number or not.
  • 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 convert string to int.
  • 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