@Test(expected = PatternSyntaxException.class) public void testSetPatternInvalid() { WTextField field = new WTextField(); field.setPattern("[foo"); }
@Override public void executeOnValid(final ActionEvent event) { String regex = pattern.getText(); textField.setPattern(regex); textField.getLabel().setHint(regex); phoneNumberField.setPattern(regex); phoneNumberField.getLabel().setHint(regex); multiTextField.setPattern(regex); multiTextField.getLabel().setHint(regex); } });
Assert.assertTrue("Text with no pattern set should be valid", diags.isEmpty()); field.setPattern(pattern);
layout.addField("Min length 20", textfield); textfield = new WTextField(); textfield.setPattern("\\d+"); layout.addField("Pattern only numbers", textfield); textfield = new WTextField(); textfield.setMaxLength(4); textfield.setColumns(4); textfield.setPattern("[0-9]{4}"); textfield.setToolTip("four numeric digits"); layout.addField("Postcode", textfield); textfield.setPattern("\\+[1-9][0-9]{0,3}"); textfield.setToolTip("plus sign (+) followed by 1 to 4 digits"); textfield.setMaxLength(6); textfield.setPattern("0[0-9]{1,5}"); textfield.setToolTip("numeric zero (0) followed by 1 to 5 digits"); textfield.setMaxLength(6); textfield.setPattern("[0-9]{1,12}"); textfield.setToolTip("up to 12 digits without spaces"); textfield.setPlaceholder("12349876"); textfield.setPattern("[0-9]{1,6}"); textfield.setToolTip("up to 6 digits without spaces"); textfield.setPlaceholder("optional"); textfield.setPattern("[0-9\\ ]{5,15}");
assertXpathEvaluatesTo(button.getId(), "//ui:textfield/@buttonId", textField); textField.setPattern(""); assertSchemaMatch(textField); assertXpathNotExists("//ui:textfield/@pattern", textField); textField.setPattern("test[123]"); assertSchemaMatch(textField); assertXpathEvaluatesTo(textField.getPattern(), "//ui:textfield/@pattern", textField);