
I have the following form(as example).
Name:_____ Id number:____
I want to handle that as if one enter numbers in place of name,my program says please enter only character place of the name.
How I should do????????
Dame Leta
From Ethiopia,Jimma University, Department of Computer Science.

import java.util.*;
import java.util.regex.*;
class RegularExpressions {
public static boolean validateName(String name) {
return name.matches("\\p{Upper}(\\p{Lower}+\\s?)");
}
public static boolean isNumeric(String str){
return str.matches("-?\\d+(.\\d+)?");
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter Name: ");
String name = input.nextLine();
while (validateName(name) != true) {
System.out.print("Invalid Name(Name and Surname shoulb be started with capitals with space between name and surname)!");
System.out.println();
System.out.print("Re-Enter Name: ");
name = input.nextLine();
}
System.out.print("Enter ID: ");
String id = input.next();
while(isNumeric(id) != true) {
System.out.print("Invalid ID!");
System.out.println();
System.out.print("Re-Enter ID: ");
id = input.next();
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.