tf.setValue("-321");
form.addField("c", tf);
tf = new TextField(
"A field, must contain a floating point number or be empty");
tf.addValidator(new DoubleValidator("Invalid double {0}"));
tf.setValue("-123.45e6");
form.addField("d", tf);
tf = new TextField(
"A field, must contain an e-mail address or be empty");
tf.addValidator(new EmailValidator("Invalid e-mail address {0}"));
tf.setValue("a.b@example.com");
form.addField("e", tf);
// regular expressions
tf = new TextField("A field, must match the regular expression a.*b.*c");
tf.addValidator(new RegexpValidator("a.*b.*c",
"{0} does not match the regular expression"));
tf.setValue("aagsabeqgc");
form.addField("f", tf);
tf = new TextField(
"A field, must contain the regular expression a.*b.*c");
tf.addValidator(new RegexpValidator("a.*b.*c", false,
"{0} does not contain the regular expression"));
tf.setValue("aagsabeqgc");
form.addField("g", tf);
tf = new TextField(
"A field, must match the regular expression ^a.*b.*c$");
tf.addValidator(new RegexpValidator("^a.*b.*c$", false,
"{0} does not match the regular expression with ^ and $"));
tf.setValue("aagsabeqgc");
form.addField("h", tf);
tf = new TextField(
"A field, must contain the regular expression ^a.*b.*c$");
tf.addValidator(new RegexpValidator("^a.*b.*c$", false,
"{0} does not contain the regular expression with ^ and $"));
tf.setValue("aagsabeqgc");
form.addField("i", tf);
// TODO CompositeValidator
tf = new TextField(
"A field, must be a floating point number with 4-5 chars");
CompositeValidator cv = new CompositeValidator(CombinationMode.AND,
"The field must contain a floating point number with 4-5 characters");
cv.addValidator(new StringLengthValidator(
"String length of '{0}' should be 4-5 characters", 4, 5, false));
cv.addValidator(new DoubleValidator(
"{0} must be a floating point number"));
tf.addValidator(cv);
tf.setValue("12.34");
form.addField("j", tf);
tf = new TextField(
"A field, must be a floating point number or 4-5 chars");
cv = new CompositeValidator(CombinationMode.OR,
"The field must contain a floating point or with 4-5 characters");
cv.addValidator(new StringLengthValidator(
"String length of '{0}' should be 4-5 characters", 4, 5, false));
cv.addValidator(new DoubleValidator(
"{0} must be a floating point number"));
tf.addValidator(cv);
tf.setValue("12.34g");
form.addField("jb", tf);