Visual Prolog:编辑控件:检查字符串是否包含数字

Visual Prolog : Edit Control : Check if string contains numbers

我们使用下面的例子来验证编辑控件只包含数字。

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())).

是否有示例验证字符串是否仅包含字母以及消息用户是否包含数字?

下面的代码添加了只允许字母的验证。 Replaceall 允许使用空格。感谢 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.