private bool FormValidator() { string pattern = @"(\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)"; string result_string = ""; bool result = true; if ((string.IsNullOrEmpty(Surname) || Surname.Length > 30)) { result_string += "Check your Surname (max length: 30)\n"; result = false; } if ((string.IsNullOrEmpty(Name) || Name.Length > 30)) { result_string += "Check your Name (max length: 30)\n"; result = false; } if ((string.IsNullOrEmpty(Email) || !Regex.IsMatch(Email, pattern))) { result_string += "Check your Email\n"; result = false; } if ((string.IsNullOrEmpty(Username) || Username.Length > 30)) { result_string += "Check your Username (max length: 30)\n"; result = false; } if ((string.IsNullOrEmpty(Password1) || Password1.Length > 30)) { result_string += "Check your Password(1) (max length: 30)\n"; result = false; } if (!(Password1 == Password2)) { result_string += "Your passwords do not match\n"; result = false; } if (result == true) { result = RegisterModel.EmailVerificator(Email); if (result == false) { result_string += "User whith this email is exists"; } result = RegisterModel.UsernameVerificator(Username); if (result == false) { result_string += "User whith this username is exists"; } } if (result) { return(true); } else { CustomMessageBox.Show(result_string); return(false); } }