-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AYS-551 | The Email Validation Fixed. #399
base: main
Are you sure you want to change the base?
Conversation
if (email.startsWith(" ") || email.endsWith(" ")) { | ||
return buildViolation(constraintValidatorContext, "email must not start or end with whitespace."); | ||
} | ||
|
||
if (email.chars().filter(ch -> ch == '@').count() != 1) { | ||
return buildViolation(constraintValidatorContext, "email must contain exactly one '@' character."); | ||
} | ||
|
||
if (email.matches(".*[()#\\[\\]\";,\\s].*")) { | ||
return buildViolation(constraintValidatorContext, "email contains invalid special characters."); | ||
} | ||
|
||
String[] parts = email.split("@", 2); | ||
if (!Character.isLetterOrDigit(parts[0].charAt(0))) { | ||
return buildViolation(constraintValidatorContext, "email local part must start with a letter or number."); | ||
} | ||
|
||
String domainPart = parts[1]; | ||
if (domainPart.startsWith("-") || domainPart.endsWith("-")) { | ||
return buildViolation(constraintValidatorContext, "domain must not start or end with a hyphen."); | ||
} | ||
|
||
if (!email.matches(EMAIL_REGEX)) { | ||
return buildViolation(constraintValidatorContext, "email is not in a valid format."); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (email.startsWith(" ") || email.endsWith(" ")) { | |
return buildViolation(constraintValidatorContext, "email must not start or end with whitespace."); | |
} | |
if (email.chars().filter(ch -> ch == '@').count() != 1) { | |
return buildViolation(constraintValidatorContext, "email must contain exactly one '@' character."); | |
} | |
if (email.matches(".*[()#\\[\\]\";,\\s].*")) { | |
return buildViolation(constraintValidatorContext, "email contains invalid special characters."); | |
} | |
String[] parts = email.split("@", 2); | |
if (!Character.isLetterOrDigit(parts[0].charAt(0))) { | |
return buildViolation(constraintValidatorContext, "email local part must start with a letter or number."); | |
} | |
String domainPart = parts[1]; | |
if (domainPart.startsWith("-") || domainPart.endsWith("-")) { | |
return buildViolation(constraintValidatorContext, "domain must not start or end with a hyphen."); | |
} | |
if (!email.matches(EMAIL_REGEX)) { | |
return buildViolation(constraintValidatorContext, "email is not in a valid format."); | |
} | |
if (email.startsWith(" ") || email.endsWith(" ")) { | |
return this.buildViolation(constraintValidatorContext, "email must not start or end with whitespace"); | |
} | |
if (email.chars().filter(ch -> ch == '@').count() != 1) { | |
return this.buildViolation(constraintValidatorContext, "email must contain exactly one '@' character"); | |
} | |
if (email.matches(".*[()#\\[\\]\";,\\s].*")) { | |
return this.buildViolation(constraintValidatorContext, "email contains invalid special characters"); | |
} | |
String[] parts = email.split("@", 2); | |
if (!Character.isLetterOrDigit(parts[0].charAt(0))) { | |
return this.buildViolation(constraintValidatorContext, "email local part must start with a letter or number"); | |
} | |
String domainPart = parts[1]; | |
if (domainPart.startsWith("-") || domainPart.endsWith("-")) { | |
return this.buildViolation(constraintValidatorContext, "domain must not start or end with a hyphen"); | |
} | |
if (!email.matches(EMAIL_REGEX)) { | |
return this.buildViolation(constraintValidatorContext, "email is not in a valid format"); | |
} |
private boolean buildViolation(ConstraintValidatorContext context, String message) { | ||
context.disableDefaultConstraintViolation(); | ||
context.buildConstraintViolationWithTemplate(message).addConstraintViolation(); | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private boolean buildViolation(ConstraintValidatorContext context, String message) { | |
context.disableDefaultConstraintViolation(); | |
context.buildConstraintViolationWithTemplate(message).addConstraintViolation(); | |
return false; | |
} | |
private boolean buildViolation(ConstraintValidatorContext constraintValidatorContext, String message) { | |
constraintValidatorContext.disableDefaultConstraintViolation(); | |
constraintValidatorContext.buildConstraintViolationWithTemplate(message).addConstraintViolation(); | |
return false; | |
} |
return this.buildViolation(constraintValidatorContext, "email must not start or end with whitespace"); | ||
} | ||
|
||
if (email.chars().filter(ch -> ch == '@').count() != 1) { | ||
return this.buildViolation(constraintValidatorContext, "email must contain exactly one '@' character"); | ||
} | ||
|
||
if (email.matches(".*[()#\\[\\]\";,\\s].*")) { | ||
return this.buildViolation(constraintValidatorContext, "email contains invalid special characters"); | ||
} | ||
|
||
|
||
String[] parts = email.split("@", 2); | ||
if (!Character.isLetterOrDigit(parts[0].charAt(0))) { | ||
return this.buildViolation(constraintValidatorContext, "email local part must start with a letter or number"); | ||
} | ||
|
||
String domainPart = parts[1]; | ||
if (domainPart.startsWith("-") || domainPart.endsWith("-")) { | ||
return this.buildViolation(constraintValidatorContext, "domain must not start or end with a hyphen"); | ||
} | ||
|
||
if (!email.matches(EMAIL_REGEX)) { | ||
return this.buildViolation(constraintValidatorContext, "email is not in a valid format"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return this.buildViolation(constraintValidatorContext, "email must not start or end with whitespace"); | |
} | |
if (email.chars().filter(ch -> ch == '@').count() != 1) { | |
return this.buildViolation(constraintValidatorContext, "email must contain exactly one '@' character"); | |
} | |
if (email.matches(".*[()#\\[\\]\";,\\s].*")) { | |
return this.buildViolation(constraintValidatorContext, "email contains invalid special characters"); | |
} | |
String[] parts = email.split("@", 2); | |
if (!Character.isLetterOrDigit(parts[0].charAt(0))) { | |
return this.buildViolation(constraintValidatorContext, "email local part must start with a letter or number"); | |
} | |
String domainPart = parts[1]; | |
if (domainPart.startsWith("-") || domainPart.endsWith("-")) { | |
return this.buildViolation(constraintValidatorContext, "domain must not start or end with a hyphen"); | |
} | |
if (!email.matches(EMAIL_REGEX)) { | |
return this.buildViolation(constraintValidatorContext, "email is not in a valid format"); | |
} | |
return this.buildViolation(constraintValidatorContext, "must not start or end with whitespace"); | |
} | |
if (email.chars().filter(ch -> ch == '@').count() != 1) { | |
return this.buildViolation(constraintValidatorContext, "must contain exactly one '@' character"); | |
} | |
if (email.matches(".*[()#\\[\\]\";,\\s].*")) { | |
return this.buildViolation(constraintValidatorContext, "contains invalid special characters"); | |
} | |
String[] parts = email.split("@", 2); | |
if (!Character.isLetterOrDigit(parts[0].charAt(0))) { | |
return this.buildViolation(constraintValidatorContext, "local part must start with a letter or number"); | |
} | |
String domainPart = parts[1]; | |
if (domainPart.startsWith("-") || domainPart.endsWith("-")) { | |
return this.buildViolation(constraintValidatorContext, "domain must not start or end with a hyphen"); | |
} | |
if (!email.matches(EMAIL_REGEX)) { | |
return this.buildViolation(constraintValidatorContext, "must be valid format"); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Buradaki mesajların geleceğine dair testleri göremedim. Her bir mesajı ayrı ayrı böldüğümüz için bence bu senaryolar için de testler eklemeliyiz.
Checklist
Before submitting your pull request, ensure the following:
Title and Branch Naming Conventions:
standard: Pull Request Naming Conventions.
the Branch Naming Conventions.
Local Testing:
Code Quality:
Documentation:
Testing:
Reviewers and Assignees:
Labels and Associations: