How to Validate a Username Using Java (Simple)

preview_player
Показать описание
How to Validate a Username Using Java (Simple)

Greetings, in this tutorial we shall be looking at how to validate a username using Java. We will be doing a range check on the length of a username to ensure it is greater than 4 characters long and less than 15 characters long.

We will also be using a regex to allow usernames that are any combination of letters, numbers and allow for underscores too. A username must contain at least some letters or numbers. A username with just underscores will be considered invalid.

You are free to customise what you want a valid username to be for your Java application. In this tutorial we will be using a range check and a regex.

Regex used in this Java tutorial to validate a username: "^(?=.*[a-zA-Z0-9])[a-zA-Z0-9_]+$"

Thanks for watching this Java tutorial on how to validate a username.

How to Validate a Username Using Java (Simple)
Рекомендации по теме