Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/edu/wright/cs/raiderplanner/controller/AccountController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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());
Expand Down
9 changes: 9 additions & 0 deletions src/edu/wright/cs/raiderplanner/model/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions src/edu/wright/cs/raiderplanner/view/CreateAccount.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@
<HBox GridPane.rowIndex="3">
<children>
<Region prefHeight="51.0" prefWidth="328.0" />
<TextField fx:id="major" promptText="Major" GridPane.hgrow="SOMETIMES" GridPane.rowIndex="3">
<GridPane.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</GridPane.margin>
<HBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</HBox.margin>
</TextField>
<Button fx:id="submit" defaultButton="true" disable="false" mnemonicParsing="false" onMouseClicked="#handleSubmit" prefHeight="31.0" prefWidth="68.0" text="OK" GridPane.rowIndex="3">
<HBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
Expand Down