密码检查程序应该输入用户名和密码,并输出密码是否有效。Java密码模式
我一直在尝试使用正则表达式,但我有一个问题。该模式适用于我所有的规则,但一个是用户名规则。 此外,有没有办法将输出从“真”或“假”更改为自定义?
我迄今为止代码:
import java.util.regex.*;
import java.util.Scanner;
public class validPassword {
private static Scanner scnr;
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// Variable Management
String un, pw, req; // Variable Variable
System.out.println("Please enter a username: ");
// ^Need to implement so if it matches the password it's invalid^
un = input.nextLine(); // Gathers user's username input
System.out.println("Please enter a password: ");
pw = input.nextLine(); // Gathers user's password input
req = "(?=.*[0-9])(?=.*[a-zA-Z]).{8,}";
System.out.println(pw.matches(req)); // Can I customize the output?
}
}
我明白任何帮助! :)
你知道,与上次编辑你改变了从“必须包含数字,小写字母和大写字母”到“必须包含的意义数字和小写**或**大写字母“?现在只需使用小写字母和大写字母即可。你是否对我的答案失去了赞同?如果是这样,为什么? – Vampire