对于标准的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"));
无论我给这个PasswordField字段输入什么,它总是报告无效。在这种情况下,我给了" abcd"作为输入。我的意图是不允许任何空格用于密码字段。如何为Vaadin PasswordField做到这一点?
答案 0 :(得分:0)
尝试使用regexpt,允许除空格之外的任何其他字符的0-n:
field.addValidator(new RegexpValidator("[^\\s]*", "Whitespace is not allowed for password field"));