如何让数据窗口中字符型字段只能录入数字和符号'-'

嘉友云阁 2011-03-04 09:08:57
字段plu_code字符型创建dw,因为特殊的需要,该字段在dw中录入只能录入数字和符号'-'
用mask和format限制格式为"##############",却只能输入数字
应该发何设置???
...全文
501 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
184270428 2011-03-07
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 eviler 的回复:]
我来收分了

在数据窗口的 editchanged 写


SQL code

If dwo.name = 'bq' Then -- 换成你的列明
if Match(data, "^[0-9-]+$") Then
Else
This.undo()
end if
End if
[/Quote]

你的回答不用测,就知道是错的。

这里的回答,没有一个用转义符的,所以都是错的!
184270428 2011-03-07
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 184270428 的回复:]
if not match('2011-03-05',"^[0-9\-]*$") then
messagebox('','NO')
else
messagebox('','YES')
end if

看看运行结果
[/Quote]

怎么没有看呢?
-是特殊字符,当然要有转义符 "\".
这么简单的问题,还试来试去
184270428 2011-03-05
  • 打赏
  • 举报
回复
if not match('2011-03-05',"^[0-9\-]*$") then
messagebox('','NO')
else
messagebox('','YES')
end if

看看运行结果
eviler 2011-03-05
  • 打赏
  • 举报
回复
看来是不重视我 的回复啊
yyoinge 2011-03-05
  • 打赏
  • 举报
回复

This.undo()

会存在undo()后数据不准确的情况,当全选后再敲字符进去还会报错
yyoinge 2011-03-05
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 xys_777 的回复:]
那就这样写editchange

int i
string lsdata
if string(dwo.name)='nm' then
for i=1 to len(data)
if not Match( mid(data,i,1) , "[0-9-]") then
continue
end if
lsdata+=mid(data,i,1)
next

this.settex……
[/Quote]



这个当光标在字符串中间时,录入后会自动跳到尾部。改良一下:
int i
int li_pos
string lsdata
if string(dwo.name)='a' then
li_pos = selectedstart( )
parent.title = string(li_pos)
for i=1 to len(data)
if not Match( mid(data,i,1) , "[0-9-]") then
li_pos --
continue
end if
lsdata+=mid(data,i,1)
next

this.settext(lsdata)
this.selecttext(li_pos,0)
end if
eviler 2011-03-04
  • 打赏
  • 举报
回复
我来收分了

在数据窗口的 editchanged 写


If dwo.name = 'bq' Then -- 换成你的列明
if Match(data, "^[0-9-]+$") Then
Else
This.undo()
end if
End if
嘉友云阁 2011-03-04
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 xys_777 的回复:]
试试用validation
Match(GetText(), "[0-9-]*")
[/Quote]
试着做了,可是用户还是可以直接在DW中输入除数字和"-"以外的字符,只不过是报个错,我想的是用户除数字和字符"-"以外,其它的按键在本列中无效
嘉友云阁 2011-03-04
  • 打赏
  • 举报
回复
是象图片这样吗???
嘉友云阁 2011-03-04
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 xys_777 的回复:]
试试用validation
Match(GetText(), "[0-9-]*")
[/Quote]


楼上,谢谢昨天你对我Access数据库时间变量查询的解答,但现在因为积分问题,却无法结贴。
关于这次的问题,你的解答我没有看太懂。
如何应用??

validation是什么,是这个字段列中的一个属性吗
永生天地 2011-03-04
  • 打赏
  • 举报
回复
试试用validation
Match(GetText(), "[0-9-]*")
嘉友云阁 2011-03-04
  • 打赏
  • 举报
回复
楼上的不对,试了,使用num的mask,那个横框只是个格式,并非真实存在的,无法正确输入,而使用edit的mask,则所有字母都可以输入了
xuam 2011-03-04
  • 打赏
  • 举报
回复
"#######-######"
jjoulejcc 2011-03-04
  • 打赏
  • 举报
回复
思路还是很多,要不你就建一个虚拟的数字字段,设置好editmask。把string类型的这个字段隐藏了,然后把输入的值赋给string类型的字段就行了
永生天地 2011-03-04
  • 打赏
  • 举报
回复
那就这样写editchange

int i
string lsdata
if string(dwo.name)='nm' then
for i=1 to len(data)
if not Match( mid(data,i,1) , "[0-9-]") then
continue
end if
lsdata+=mid(data,i,1)
next

this.settext(lsdata)
this.selecttext(len(data)+1,len(data)+2)

end if
wag_enu 2011-03-04
  • 打赏
  • 举报
回复
band()

1,109

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧