zkoss textbox constraint =" / \ p {InCyrillic} * /"

时间:2013-08-01 16:21:32

标签: unicode textbox constraints zk zul

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

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

1 个答案:

答案 0 :(得分: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}*)$"));