Question

I'm using a EmailTextField in a wicket 1.5 app in order to log users. According to GMail alias, a + symbol may be present in email but wicket doesn't allow it. Is there a way to accept extra symbol in the validator?

Was it helpful?

Solution

You have to write your own validator:

public class GMailAddressValidator extends PatternValidator {

    public GMailAddressValidator() {
        super("^[_A-Za-z0-9-+]+(\\.[_A-Za-z0-9-+]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*((\\.[A-Za-z]{2,}){1}$)",
                Pattern.CASE_INSENSITIVE);
    }
}

Here I just add two pluses to original Wicket regexp for validating e-mails (tried to highlight pluses in bold):

^[_A-Za-z0-9-+]+(\\.[_A-Za-z0-9-+]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*((\\.[A-Za-z]{2,}){1}$)

After that you could use simple TextField with your validator instead of EmailTextField. Like that:

new TextField<String>("email").add(new GMailAddressValidator())

OTHER TIPS

I think you will have to override the HTML5 validation like this: Override html5 validation, the component only sets the input type to email, i dont think it adds any wicket validation. If you dont want to add the js override, the best thing todo would be to create your own validator for a wicket TextField.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top