Validate Strong Username
This program validates username using regex.
Problem Statement
Write a Java program to validate username with only letters, digits, underscore, length 515.
Source Code
| 1 | public class RegexUsernameValidation { |
| 2 | public static void main(String[] args) { |
| 3 | System.out.println("Eduinq Regex Username Validation"); |
| 4 | String user="Eduinq_123"; |
| 5 | String regex="^[A-Za-z0-9_]{5,15}$"; |
| 6 | if(user.matches(regex)) System.out.println("Valid username"); |
| 7 | else System.out.println("Invalid username"); |
| 8 | } |
| 9 | } |
Program Output
Eduinq Regex Username Validation Valid username
Explanation
Regex checks allowed characters and length. - matches() validates username. - Together demonstrates regex validation. Conclusion: Shows how to validate username using regex.