@@ -164,15 +164,21 @@ public void updateItem(LocalDate date, boolean empty) {
164
164
txtPhoneNumber .getValidators ().add (phoneNumberValidation );
165
165
phoneNumberValidation .setMessage ("Phone Number is required!" );
166
166
167
+ RegexValidator userRegexValidation = new RegexValidator ();
168
+ String regexUsername = "^[a-zA-Z]([._](?![._])|[a-zA-Z0-9]){3,18}[a-zA-Z0-9]$" ;
169
+ userRegexValidation .setRegexPattern (regexUsername );
170
+ userRegexValidation .setMessage ("Your Username is not valid" );
171
+ txtUserName .getValidators ().add (userRegexValidation );
172
+
167
173
RegexValidator emailRegexValidator = new RegexValidator ();
168
- String RegexEmail = "^(?=.{1,64}@)[A-Za-z0-9_-]+(\\ .[A-Za-z0-9_-]+)*@[^-][A-Za-z0-9-]+(\\ .[A-Za-z0-9-]+)*(\\ .[A-Za-z]{2,})$" ;
169
- emailRegexValidator .setRegexPattern (RegexEmail );
174
+ String regexEmail = "^(?=.{1,64}@)[A-Za-z0-9_-]+(\\ .[A-Za-z0-9_-]+)*@[^-][A-Za-z0-9-]+(\\ .[A-Za-z0-9-]+)*(\\ .[A-Za-z]{2,})$" ;
175
+ emailRegexValidator .setRegexPattern (regexEmail );
170
176
emailRegexValidator .setMessage ("Your Email is not valid" );
171
177
txtEmail .getValidators ().add (emailRegexValidator );
172
178
173
179
RegexValidator phoneRegexValidator = new RegexValidator ();
174
- String RegexPhone = "(84|0[3|5|7|8|9])+([0-9]{8})\\ b" ;
175
- phoneRegexValidator .setRegexPattern (RegexPhone );
180
+ String regexPhone = "(84|0[3|5|7|8|9])+([0-9]{8})\\ b" ;
181
+ phoneRegexValidator .setRegexPattern (regexPhone );
176
182
phoneRegexValidator .setMessage ("Your Phone Number is not valid" );
177
183
txtPhoneNumber .getValidators ().add (phoneRegexValidator );
178
184
@@ -231,10 +237,10 @@ public void updateItem(LocalDate date, boolean empty) {
231
237
232
238
//Add Employee
233
239
btnAdd .setOnAction (event -> {
234
- if (txtUserName .getText ().equals ("" ) || txtPassword .getText ().equals ("" ) || txtReEnterPassword .getText ().equals ("" ) ||
240
+ if (txtUserName .getText ().equals ("" ) || ! txtUserName . getText (). matches ( regexUsername ) || txtPassword .getText ().equals ("" ) || txtReEnterPassword .getText ().equals ("" ) ||
235
241
txtFullName .getText ().equals ("" ) || txtNoID .getText ().equals ("" ) || txtAddress .getText ().equals ("" ) ||
236
- txtEmail .getText ().equals ("" ) || !txtEmail .getText ().matches (RegexEmail ) ||
237
- txtPhoneNumber .getText ().equals ("" ) || !txtPhoneNumber .getText ().matches (RegexPhone )) {
242
+ txtEmail .getText ().equals ("" ) || !txtEmail .getText ().matches (regexEmail ) ||
243
+ txtPhoneNumber .getText ().equals ("" ) || !txtPhoneNumber .getText ().matches (regexPhone )) {
238
244
txtUserName .validate ();
239
245
txtPassword .validate ();
240
246
txtReEnterPassword .validate ();
@@ -248,8 +254,8 @@ public void updateItem(LocalDate date, boolean empty) {
248
254
checkPassword ();
249
255
emailIsExist ();
250
256
phoneNumberIsExist ();
251
- if (!userNameisExist () && checkPassword () && txtEmail .getText ().matches (RegexEmail ) && !emailIsExist () &&
252
- txtPhoneNumber .getText ().matches (RegexPhone ) && !phoneNumberIsExist ()) {
257
+ if (!userNameisExist () && txtUserName . getText (). matches ( regexUsername ) && checkPassword () && txtEmail .getText ().matches (regexEmail ) && !emailIsExist () &&
258
+ txtPhoneNumber .getText ().matches (regexPhone ) && !phoneNumberIsExist ()) {
253
259
addTableAccount ();
254
260
addTableProfile ();
255
261
0 commit comments