Finding Enter Numbers in Word format

edited December 2022 in Flutter

we can check if the entered data contains numbers in word format like one, two, three..., we can use the below code

first take a list of words that we want to recognize from the entered field,

List<String> wordsList = [
  "zero",
  "one",
  "two",
  "three",
  "four",
  "five",
  "six",
  "seven",
  "eight",
  "nine",
  "ten"
];


code:

int j = 0;
for (int i = 0; i < wordsList.length; i++) {
  if (descriptionController.text
      .toString()
      .toLowerCase()
      .trim()
      .replaceAll(RegExp(r"\s+\b|\b\s"), "")
      .contains(wordsList[i])) {
    break;
  } else {
    j = j + 1;
  }
}

if (j != 11) {
  //entered data contan words in number format
}else{
//not contain any number in in word format
}


Sign In or Register to comment.