为什么Vaadin 7 PasswordField验证不起作用

时间:2018-05-20 06:17:26

标签: java vaadin7

对于标准的Java正则表达式,工作正常: -

    Pattern pattern = Pattern.compile("\\s");
    Matcher matcher = pattern.matcher("space here");
    Matcher matcher2 = pattern.matcher("noSpaceHere");
    boolean foundSpace = matcher.find();
    boolean noSpace = matcher.find();
    System.out.println("Space found "+foundSpace);
    System.out.println("Any space found "+noSpace);

我认为vadin应该是一样的。但它不起作用: -

PasswordField field = new PasswordField((String) processConfig.get("name"));
field.setWidth("100%");
field.addValidator(new RegexpValidator("\\s", "Whitespace is not allowed for password field"));

截图: -  enter image description here

无论我给这个PasswordField字段输入什么,它总是报告无效。在这种情况下,我给了" abcd"作为输入。我的意图是不允许任何空格用于密码字段。如何为Vaadin PasswordField做到这一点?

1 个答案:

答案 0 :(得分:0)

尝试使用regexpt,允许除空格之外的任何其他字符的0-n:

field.addValidator(new RegexpValidator("[^\\s]*", "Whitespace is not allowed for password field"));