@@ -164,15 +164,21 @@ public void updateItem(LocalDate date, boolean empty) {
164164 txtPhoneNumber .getValidators ().add (phoneNumberValidation );
165165 phoneNumberValidation .setMessage ("Phone Number is required!" );
166166
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+
167173 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 );
170176 emailRegexValidator .setMessage ("Your Email is not valid" );
171177 txtEmail .getValidators ().add (emailRegexValidator );
172178
173179 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 );
176182 phoneRegexValidator .setMessage ("Your Phone Number is not valid" );
177183 txtPhoneNumber .getValidators ().add (phoneRegexValidator );
178184
@@ -231,10 +237,10 @@ public void updateItem(LocalDate date, boolean empty) {
231237
232238 //Add Employee
233239 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 ("" ) ||
235241 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 )) {
238244 txtUserName .validate ();
239245 txtPassword .validate ();
240246 txtReEnterPassword .validate ();
@@ -248,8 +254,8 @@ public void updateItem(LocalDate date, boolean empty) {
248254 checkPassword ();
249255 emailIsExist ();
250256 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 ()) {
253259 addTableAccount ();
254260 addTableProfile ();
255261
0 commit comments