Java tutorial
public class Main { public static void main(String[] args) { boolean flag = true; String str = "123"; for (int i = 0; i < str.length(); i++) { if (str.charAt(i) > 48 && str.charAt(i) < 58) { flag = false; break; } } if (flag == true) { System.out.println("String is a valid String.."); } else { System.out.println("String contains number"); } } }