Android TextUtils.isDigitsOnly returns true for an empty string

android.text.TextUtils.isDigitsOnly("") 

I use the code above to check the input string - is it a valid number or not, but the isDigitOnly() function isDigitOnly() true for an empty string.

How to make it return false for an empty string or is there another Android build function?

+5
source share
1 answer

Do it like this:

 boolean myIsDigitsOnly(String str) { if(str.isEmpty()) { return false; } else { return TextUtils.isDigitsOnly(str); } } 

Now you call your own method:

 myIsDigitsOnly(""); // returns false 

Like Selvin mentioned correctly, this is actually a mistake that persists to this day. See here .

+6
source

Source: https://habr.com/ru/post/1269225/


All Articles