-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathANTIKEYLISTInputValidation.java
More file actions
33 lines (27 loc) · 1.09 KB
/
ANTIKEYLISTInputValidation.java
File metadata and controls
33 lines (27 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.Scanner;
public class ANTIKEYLISTInputValidation {
// Define the approved characters for validation
private static final String approvedChars = "3479ACDEFGHJKMNPQRTUVWXYacdefghjkmnpqrtuvwy@#$%^&*_+=";
// Function to validate input based on the approved characters
public static boolean validateInput(String userInput) {
for (int i = 0; i < userInput.length(); i++) {
if (approvedChars.indexOf(userInput.charAt(i)) == -1) {
return false; // Invalid character found
}
}
return true; // All characters are valid
}
// Main method to test input validation
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a string to validate: ");
String userInput = scanner.nextLine();
// Validate user input
if (validateInput(userInput)) {
System.out.println("Input is valid.");
} else {
System.out.println("Input contains invalid characters.");
}
scanner.close();
}
}