Check if string is number in android Check if string is number in android android android

Check if string is number in android


Use string.matches method which accepts a regex as an argument.

if(string.matches("\\d+(?:\\.\\d+)?")){System.out.println("Matches");}else{System.out.println("No Match");}


If you are looking for a way to just check if the string contains digits (so check for integer values), use the native TextUtils.isDigitsOnly(CharSequence str).


If you are inflating those textviews from xml you can just use:

android:inputType="number"