diff --git a/src/edu/wright/cs/raiderplanner/controller/AccountController.java b/src/edu/wright/cs/raiderplanner/controller/AccountController.java index 982c2b9..0683d04 100644 --- a/src/edu/wright/cs/raiderplanner/controller/AccountController.java +++ b/src/edu/wright/cs/raiderplanner/controller/AccountController.java @@ -54,6 +54,7 @@ public class AccountController implements Initializable { @FXML private TextField fullName; @FXML private TextField email; @FXML private CheckBox famLast; + @FXML private TextField major; @FXML private Button submit; @FXML private GridPane pane; @FXML private Alert invalidInputAlert = new Alert(AlertType.ERROR); @@ -130,6 +131,26 @@ public boolean validateEmail() { } } + /** + * Determines if the user has entered a valid major, checking if the textfield + * is empty and by calling the validateMajor() from the Person Class in + * Model, which checks that the entered Major only contains a combination + * of spaces and upper/lower case letters and returns a boolean value. + * Then sets the style so it is cohesive. + * @returns True if the user entered a valid name. + */ + + public boolean validateMajor() { + if(this.major.getText().trim().isEmpty() + || Person.validMajor(this.major.getText().trim())) { + this.major.setStyle(""); + return true; + } else { + return false; + } + } + + /** * Determines if the user has entered a valid account number by checking * that the length of the text is 7, that the first character is a 'w', @@ -191,6 +212,11 @@ public void handleSubmit() { validName = false; } } + if (!validateMajor()) { + invalidMessage += "Please enter a valid major\n"; + validSuccess = false; + } + if (validSuccess && validName) { Person pers = new Person(this.salutation.getSelectionModel().getSelectedItem().trim(), this.fullName.getText().trim(), this.famLast.isSelected()); diff --git a/src/edu/wright/cs/raiderplanner/model/Person.java b/src/edu/wright/cs/raiderplanner/model/Person.java index f59cfae..01d9ae9 100644 --- a/src/edu/wright/cs/raiderplanner/model/Person.java +++ b/src/edu/wright/cs/raiderplanner/model/Person.java @@ -346,6 +346,15 @@ public static boolean validEmail(String email) { public static boolean validName(String name) { return nameRegex.matcher(name).matches(); } + + /** + * Checks whether the given String is a valid major. + * @param major The major to validate + * @return true if the major is valid, false otherwise + */ + public static boolean validMajor(String major) { + return nameRegex.matcher(major).matches(); + } /** * Checks whether the given String is a valid salutation. diff --git a/src/edu/wright/cs/raiderplanner/view/CreateAccount.fxml b/src/edu/wright/cs/raiderplanner/view/CreateAccount.fxml index af5a7db..ef90a92 100644 --- a/src/edu/wright/cs/raiderplanner/view/CreateAccount.fxml +++ b/src/edu/wright/cs/raiderplanner/view/CreateAccount.fxml @@ -66,6 +66,14 @@ + + + + + + + +