在用写程序的时候,往往会用到正则表达式,不仅仅是Web开发,MFC、GTK+、Qt开发的图形界面也是如此,只要了解其原理,语法也都大相径庭!
1、非汉字(6-20位)
常例:密码框
QRegExp password_reg_exp("[^\u4E00-\u9FA5]{6,20}");
QRegExpValidator* password_validator = new QRegExpValidator(password_reg_exp);
QLineEdit* password_line_edit = new QlineEdit();
password_line_edit->setText(QString("密码正则ok"));
QString password = password_line_edit->text();
if (!password_validator->regExp().exactMatch(password))
{
return false;
}
2、字母、数字、下划线组成(4-30位)
常例:用户名
QRegExp user_reg_exp("[A-Za-z0-9_]{6,30}");
3、整形范围
常例:端口
QIntValidator *int_validator = new QIntValidator(0, 65535);
QLineEdit *int_edit = new QLineEdit();
int_edit ->setValidator(int_validator );
感谢您的观看,对您有用就分享出去吧 !
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容