Checking if string is numeric in dart

后端 未结 4 1118
悲哀的现实
悲哀的现实 2021-02-02 06:59

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



        
4条回答
  •  迷失自我
    2021-02-02 07:32

    for anyone wanting a non native way using regex

    RegExp _numeric = RegExp(r'^-?[0-9]+$');
    
    /// check if the string contains only numbers
     bool isNumeric(String str) {
    return _numeric.hasMatch(str);
    }
    

提交回复
热议问题