我们使用以下示例来验证该编辑控件仅包含数字。
class predicates
validateNumber : control::validateResponder.
clauses
validateNumber(Control) = control::contentsOk :-
hasDomain(integer, _X),
_X = trytoTerm(Control:getText()),
!.
validateNumber(Control) = control::contentsInvalid(Control, Control,
string::format("%s must be an integer!", Control:getLabel())).
是否有示例验证字符串是否仅包含字母和消息用户是否包含数字?
下面的代码添加了仅允许字母的验证。替换允许使用空间。感谢Gukalov在讨论中提供答案。视觉原理。com
class predicates
allowonlyalphabets : control::validateResponder.
clauses
allowonlyalphabets(Control) =
if string::hasAlpha(string::replaceAll(Control:getText(), " ", "")) then
control::contentsOk
else
control::contentsInvalid(Control, Control,
string::format("%s must not contain numbers!", Control:getLabel()))
end if.