0

为什么它不适用于正则表达式 \p{InCyrillic}?我试过 \p{L} 但它也不起作用。我在 zul 中的代码:

textbox  id="box" hflex="1" constraint="/\p{InCyrillic}*/"
4

1 回答 1

0

实现了自己的约束:

package com.upc.webcallcentr4zk.controller.constraints;

import java.io.Serializable;
import java.util.regex.Pattern;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.WrongValueException;
import org.zkoss.zul.Constraint;
import org.zkoss.zul.Textbox;

public class PatterenCostraints implements Constraint, Serializable {

    private static final long serialVersionUID = 4052163775381888061L;
    private Pattern pattern;

    public PatterenCostraints(String pattern) {
        this.pattern = Pattern.compile(pattern);
    }

    @Override
    public void validate(Component comp, Object value) throws WrongValueException {
        if (comp instanceof Textbox) {
            String enteredValue = (String) value;
            if (enteredValue.isEmpty()) {
                throw new WrongValueException(comp, "Bla bla bla!");
            } else if (!pattern.matcher(enteredValue).matches()) {
                throw new WrongValueException(comp, "Bla bla bla!");
            }
        }
    }
}

之后:

keywordBox.setConstraint(new PatterenCostraints("^(\\p{IsCyrillic}*)$"));
于 2013-08-02T12:10:26.077 回答