So I am trying to take an input for date of birth in the from of DD/MM/YYYY the input cannot exceed 10 characters in length and I must make sure it is in the proper format to avoid the user inputting something like A51/1/1982, I think I have it written correctly at least to my knowledge :) but I am now forever stuck in the while loop when checking the input
System.out.println("Please enter your date of birth in the format DD/MM/YYYY");
dateOfBirth = scanner.nextLine(); //Read date of birth
dob0 = dateOfBirth.substring(0);// to check char 0 is between 0-3
dob1 = dateOfBirth.substring(1);// to check char 1 is between 0-9
dob2 = dateOfBirth.substring(2);// to check char 2 is between /
dob3 = dateOfBirth.substring(3);// to check char 3 is between 0-1
dob4 = dateOfBirth.substring(4);// to check char 4 is between 0-9
dob5 = dateOfBirth.substring(5);// to check char 5 is between /
dob6 = dateOfBirth.substring(6);// to check char 6 is between 1-2
dob7 = dateOfBirth.substring(7);// to check char 7 is between 0-9
dob8 = dateOfBirth.substring(8);// to check char 8 is between 0-9
dob9 = dateOfBirth.substring(9);// to check char 9 is between 0-9
dob = dateOfBirth.length(); //convert string to int to check length
while (dob !=10 || !dob0.matches("[0-3]+") || !dob1.matches("[0-9]+") || !dob2.matches("[/]+")
|| !dob3.matches("[0-1]+") || !dob4.matches("[0-9]+") || !dob5.matches("[/]+")
|| !dob6.matches("[1-2]+") || !dob7.matches("[0-9]+") || !dob8.matches("[0-9]+")
|| !dob9.matches("[0-9]+"))//check all values
{
System.out.println("Please make sure you enter your date of birth in the format DD/MM/YYYY");
dateOfBirth = scanner.nextLine();
}
I am guessing I have probably gone the long away around this bue any help would be appreciated :)
Thanks