106 lines
2.8 KiB
Markdown
106 lines
2.8 KiB
Markdown
|
---
|
|||
|
title: 编辑框数据有效性判断
|
|||
|
updated: 2022-03-14 07:46:12Z
|
|||
|
created: 2022-01-17 02:27:09Z
|
|||
|
tags:
|
|||
|
- 数据筛选
|
|||
|
---
|
|||
|
|
|||
|
数据有效性判断可分为两个部分,一是对单次输入的数字判断,滤除无效字符,二是输入完毕后对整个数据进行判断,如区间检查等
|
|||
|
# 过滤单个字符
|
|||
|
在输入时限制无效字符输入
|
|||
|
```js
|
|||
|
winform.plus.editBox.wndproc = function(hwnd,message,wParam,lParam){
|
|||
|
if(message == 0x102/*_WM_CHAR*/){//对输入字符进行约束,不能识别非eng输入法状态下的输入
|
|||
|
if(wParam >= '0'# and wParam <= '9'#){
|
|||
|
return ;
|
|||
|
}
|
|||
|
destr = wParam
|
|||
|
select(wParam) {
|
|||
|
case '-'# {
|
|||
|
if(min > 0){
|
|||
|
return 1;
|
|||
|
}
|
|||
|
if(tmp2){
|
|||
|
key.press(0x8/*_VK_BACK*/)
|
|||
|
}
|
|||
|
if(string.indexOf(ctrl.text,'-')){
|
|||
|
ctrl.text = string.trimleft(ctrl.text,"-")
|
|||
|
ctrl.setsel(tmp-1)
|
|||
|
return 1;
|
|||
|
}
|
|||
|
else {
|
|||
|
ctrl.text = string.concat("-",ctrl.text)
|
|||
|
ctrl.setsel(tmp+1)
|
|||
|
return 1;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
case 'e'#, 'E'# {
|
|||
|
if(!string.indexOf(ctrl.text,'E') and !string.indexOf(ctrl.text,'e')){
|
|||
|
return;
|
|||
|
}
|
|||
|
}
|
|||
|
case '.'# {
|
|||
|
if(!string.indexOf(ctrl.text,'.')){
|
|||
|
return ;
|
|||
|
}
|
|||
|
}
|
|||
|
case 'g'#, 'G'# {
|
|||
|
if(tmp2){
|
|||
|
key.press(0x8/*_VK_BACK*/)
|
|||
|
}
|
|||
|
if(ctrl.text != ""){
|
|||
|
ctrl.text = tonumber(ctrl.text) * 1e3
|
|||
|
ctrl.setsel(-1)
|
|||
|
}
|
|||
|
return 1;
|
|||
|
}
|
|||
|
case 'm'#, 'M'# {
|
|||
|
if(tmp2){
|
|||
|
key.press(0x8/*_VK_BACK*/)
|
|||
|
}
|
|||
|
if(ctrl.text != ""){
|
|||
|
ctrl.text = tonumber(ctrl.text) * 1e0
|
|||
|
ctrl.setsel(-1)
|
|||
|
}
|
|||
|
return 1;
|
|||
|
}
|
|||
|
case 'k'#, 'K'# {
|
|||
|
if(tmp2){
|
|||
|
key.press(0x8/*_VK_BACK*/)
|
|||
|
}
|
|||
|
if(ctrl.text != ""){
|
|||
|
ctrl.text = tonumber(ctrl.text) / 1e3
|
|||
|
ctrl.setsel(-1)
|
|||
|
}
|
|||
|
return 1;
|
|||
|
}
|
|||
|
case 0x11/*_VK_CTRL*/{
|
|||
|
if(!tmp2){
|
|||
|
var str = string.slice(ctrl.text,tmp,tmp2);
|
|||
|
if(#tonumber(str) == #str){
|
|||
|
//左侧数字+1
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
return 1; //其余字符全部屏蔽
|
|||
|
}
|
|||
|
```
|
|||
|
|
|||
|
# 检查单次数据
|
|||
|
在编辑框更新后判断上限有效性
|
|||
|
```js
|
|||
|
case 0x300/*_EN_CHANGE*/ {
|
|||
|
if(tonumber(owner.text) >= 1e3){//判断新数据范围
|
|||
|
owner.text = lstValue//无效时恢复最后一次有效数据
|
|||
|
owner.setsel(tmp)//恢复光标位置
|
|||
|
}
|
|||
|
lstValue = owner.text//更新最后一次有效数据
|
|||
|
}
|
|||
|
```
|
|||
|
在失去焦点后评断下限有效性
|
|||
|
|
|||
|
|
|||
|
#数据筛选
|