密码规则正则校验

#记录工作#

  • 字母,数字,特殊字符,3选2,长度在8-26位
^(?=.*[A-Za-z])(?=.*[\d!@#$%^&*_-])[A-Za-z\d!@#$%^&*_-]{8,26}$|^(?=.*\d)(?=.*[A-Za-z!@#$%^&*_-])[A-Za-z\d!@#$%^&*_-]{8,26}$|^(?=.*[!@#$%^&*_-])(?=.*[A-Za-z\d])[A-Za-z\d!@#$%^&*_-]{8,26}$

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
是的,为了保证密码的安全性,我们需要对密码进行正则校验。以下是修改后的代码: ```cpp #include <QApplication> #include <QWidget> #include <QLabel> #include <QLineEdit> #include <QPushButton> #include <QRegExpValidator> int main(int argc, char *argv[]) { QApplication a(argc, argv); QWidget window; window.setWindowTitle("QQ 登录"); QLabel *accountLabel = new QLabel("账号:", &window); accountLabel->move(70, 80); QLineEdit *accountLineEdit = new QLineEdit(&window); accountLineEdit->move(120, 80); QLabel *passwordLabel = new QLabel("密码:", &window); passwordLabel->move(70, 120); QLineEdit *passwordLineEdit = new QLineEdit(&window); passwordLineEdit->setEchoMode(QLineEdit::Password); passwordLineEdit->move(120, 120); // 使用正则表达式校验密码 QRegExp regExp("[a-zA-Z0-9]{6,18}"); QRegExpValidator *validator = new QRegExpValidator(regExp, passwordLineEdit); passwordLineEdit->setValidator(validator); QPushButton *loginButton = new QPushButton("登录", &window); loginButton->move(150, 160); window.resize(400, 300); window.show(); return a.exec(); } ``` 在这个示例中,我们使用了 QRegExp 和 QRegExpValidator 类来对密码进行正则校验。首先,我们创建了一个 QRegExp 对象,用于表示密码规则,这里表示密码必须由 6 到 18 位的字母或数字组成。然后,我们创建了一个 QRegExpValidator 对象,并将其绑定到密码输入框上,这样用户在输入密码时就会自动进行校验。最后,我们启动应用程序并显示窗口。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值