Methode validateData ergänzt
This commit is contained in:
parent
3c51ebbc21
commit
d858ff8f8d
@ -5,6 +5,9 @@ import java.nio.file.Paths;
|
||||
import java.sql.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Data is a class to edit files.
|
||||
@ -223,5 +226,70 @@ public class Data {
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* The method validates the user input
|
||||
*
|
||||
* @return boolean inputValid
|
||||
* @author Kevin Maier
|
||||
*/
|
||||
private boolean validateData(String password, String phoneNumber)
|
||||
{
|
||||
boolean inputValid = false;
|
||||
boolean phoneNumberMatchFound;
|
||||
boolean passwordMatchFound;
|
||||
boolean phoneNumberValid = false;
|
||||
boolean passwordValid = false;
|
||||
|
||||
Pattern phoneNumberPattern = Pattern.compile("[0-9]*");
|
||||
Pattern passwordPattern = Pattern.compile("^[^a-zA-Z0-9].*[0-9]$");
|
||||
|
||||
Scanner reader = new Scanner(System.in);
|
||||
|
||||
while(password.isEmpty() || phoneNumber.isEmpty())
|
||||
{
|
||||
System.out.println("Login fehlgeschlagen. Eingabe ist leer, versuchen Sie es erneut.");
|
||||
System.out.println("");
|
||||
System.out.print("Telefonnummer: ");
|
||||
phoneNumber = reader.nextLine();
|
||||
System.out.print("Passwort: ");
|
||||
password = reader.nextLine();
|
||||
}
|
||||
|
||||
Matcher phoneNumberMatcher = phoneNumberPattern.matcher(phoneNumber);
|
||||
Matcher passwordMatcher = passwordPattern.matcher(password);
|
||||
|
||||
phoneNumberMatchFound = phoneNumberMatcher.find();
|
||||
passwordMatchFound = passwordMatcher.find();
|
||||
|
||||
while (!inputValid) {
|
||||
if (!phoneNumberMatchFound || phoneNumber.length() != 15) {
|
||||
System.out.println("Login fehlgeschlagen. Die eingegebene Handynummer ist nicht valide.");
|
||||
System.out.println("");
|
||||
System.out.print("Telefonnummer: ");
|
||||
phoneNumber = reader.nextLine();
|
||||
System.out.print("Passwort: ");
|
||||
password = reader.nextLine();
|
||||
} else {
|
||||
phoneNumberValid = true;
|
||||
}
|
||||
|
||||
if (!passwordMatchFound || password.length() < 6 || password.length() > 20) {
|
||||
System.out.println("Login fehlgeschlagen. Das eingegebene Passwort ist nicht valide.");
|
||||
System.out.println("");
|
||||
System.out.print("Telefonnummer: ");
|
||||
phoneNumber = reader.nextLine();
|
||||
System.out.print("Passwort: ");
|
||||
password = reader.nextLine();
|
||||
} else {
|
||||
passwordValid = true;
|
||||
}
|
||||
|
||||
if (phoneNumberValid && passwordValid) {
|
||||
inputValid = true;
|
||||
}
|
||||
}
|
||||
return inputValid;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user