3.7 C
New York
Tuesday, February 7, 2023

How to check numeric strings in Flutter and Dart

A numeric string is just a number in string format.

Examples of numeric strings:Advertisements


To check whether a string is a numeric string, you can use the double.tryParse() method. If the return equals null then the input is not a numeric string, otherwise, it is.

if(double.tryParse(String input) == null){
   print('The input is not a numeric string');
} else {
   print('Yes, it is a numeric string');


The code:

void main() {
  var a = '-33.230393399';
  var b = 'ABC123';

  if (double.tryParse(a) != null) {
    print('a is a numeric string');
  } else {
    print('a is NOT a numeric string');

  if (double.tryParse(b) != null) {
    print('b is a numeric string');
  } else {
    print('b is NOT a numeric string');


a is a numeric string
b is NOT a numeric string

Hope this helps. Further reading:

You can also take a tour around our Flutter topic page and Dart topic page to see the latest tutorials and examples.

Related Articles


Please enter your comment!
Please enter your name here

Latest Articles