0
0
Spring Bootframework~10 mins

@Email and @Pattern in Spring Boot - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to validate an email field using the correct annotation.

Spring Boot
public class User {
    @[1]
    private String email;
}
Drag options to blanks, or click blank then click option'
ASize
BPattern
CNotNull
DEmail
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Pattern without a regex for email.
Using @NotNull which only checks for null values.
2fill in blank
medium

Complete the code to validate a username with only letters and digits using @Pattern.

Spring Boot
public class User {
    @Pattern(regexp = "[1]")
    private String username;
}
Drag options to blanks, or click blank then click option'
A^[a-zA-Z0-9]+$
B^\\d+$
C^[a-z]+$
D^.+$"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a regex that allows special characters.
Forgetting to use anchors ^ and $.
3fill in blank
hard

Fix the error in the @Pattern regex to allow emails with dots and dashes.

Spring Boot
public class User {
    @Pattern(regexp = "[1]")
    private String email;
}
Drag options to blanks, or click blank then click option'
A^[a-zA-Z0-9]+@[a-zA-Z0-9]+\\.[a-zA-Z]+$
B^[a-zA-Z0-9]+@[a-zA-Z0-9]+$
C^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}$
D^[a-zA-Z0-9]+$"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a regex that does not allow dots or dashes.
Using a regex that does not validate the domain properly.
4fill in blank
hard

Fill both blanks to validate a password with at least 8 characters and only letters and digits.

Spring Boot
public class User {
    @Pattern(regexp = "[1]")
    @Size(min = [2])
    private String password;
}
Drag options to blanks, or click blank then click option'
A^[a-zA-Z0-9]+$
B8
C6
D^[a-z]+$"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a regex that allows special characters.
Setting the minimum size too low.
5fill in blank
hard

Fill all three blanks to validate a phone number with exactly 10 digits using @Pattern and @Size.

Spring Boot
public class User {
    @Pattern(regexp = "[1]")
    @Size(min = [2], max = [3])
    private String phoneNumber;
}
Drag options to blanks, or click blank then click option'
A^\\d+$
B10
D^[a-zA-Z]+$"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a regex that allows letters.
Setting min and max size differently.