正则表达式,PyQt4--QLineEdit内引入正则表达式

from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys
QTextCodec.setCodecForTr(QTextCodec.codecForName("utf8"))
class FindCell(QDialog):
def __init__(self,parent=None):
super(FindCell,self).__init__(parent)
self.setWindowTitle('Find Cell')
lblFind=QLabel('Cell Find')
editFind=QLineEdit()
btnOk=QPushButton('OK')
btnCancel=QPushButton('Cancel')
regExp=QRegExp('[A-Za-z][1-9][0-9]{0,2}')
editFind.setValidator(QRegExpValidator(regExp,self))
mainLayout=QGridLayout(self)
mainLayout.addWidget(lblFind,0,0)
mainLayout.addWidget(editFind,0,1,1,2)
mainLayout.addWidget(btnOk,1,1)
mainLayout.addWidget(btnCancel,1,2)
app=QApplication(sys.argv)
dlg=FindCell()
dlg.show()
sys.exit(app.exec_())
editFind内只有这样的输入才是合法的:
以一个字母打头,大小写均可,后面跟一个1~9之间的数字,后面再跟0~2个0至9之间的数字
例如:
A123 可以输入
A1 可以输入
A1234 不能输入
Tags:  正则表达式数字 常用正则表达式 php正则表达式 js正则表达式 正则表达式

延伸阅读

最新评论

发表评论