Skip to content

Commit

Permalink
Adding validations in create user API for firstName
Browse files Browse the repository at this point in the history
  • Loading branch information
sreeragksgh committed Jun 12, 2024
1 parent 8585472 commit e24cbbc
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public void validateCreateUserRequest(Request userRequest) {
validateUserType(userRequest.getRequest(), null, userRequest.getRequestContext());
phoneValidation(userRequest);
validatePassword((String) userRequest.getRequest().get(JsonKey.PASSWORD));
validateFirstName(userRequest);
}

public static boolean isGoodPassword(String password) {
Expand All @@ -80,6 +81,20 @@ private void validatePassword(String password) {
}
}

private void validateFirstName(Request userRequest) {
String firstName = (String) userRequest.getRequest().get(JsonKey.FIRST_NAME);
String[] words = firstName.split("\\s+");
StringBuilder modifiedFirstName = new StringBuilder();
for (String word : words) {
if (word.length() > 0) {
modifiedFirstName.append(Character.toUpperCase(word.charAt(0)))
.append(word.substring(1).toLowerCase())
.append(" ");
}
}
userRequest.getRequest().put(JsonKey.FIRST_NAME,modifiedFirstName);
}

/**
* This method will validate location type
*
Expand Down

0 comments on commit e24cbbc

Please sign in to comment.