X{n,m} == "greedy quantifier"
X, at least n but not more than m times |
http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html
http://en.wikipedia.org/wiki/Email_address
full implementation of email regex validation: http://code.iamcal.com/php/rfc822/full_regexp.txt
practical implementation: http://www.mkyong.com/regular-expressions/how-to-validate-email-address-with-regular-expression/
so here's what i came up with:
if (!Pattern.compile("[A-Za-z0-9\\._\\-]+\\@[A-Za-z0-9\\-]+(\\.[A-Za-z0-9\\-]+)*(\\.[A-Za-z]{2,})").matcher(mail).find()){
throw new ValidatorException(new FacesMessage("Invalid email."));
}
i ended up choosing "X, at least n but not more than m times".
here are examples of valid emails checked against my regexp above:
ric-k.g.mum-phrey@g-mail.com
rick.g.mumphrey@gmail.com
rick.g.mumphrey@gmail.co.uk
here are examples of valid emails checked against my regexp above:
ric-k.g.mum-phrey@g-mail.com
rick.g.mumphrey@gmail.com
rick.g.mumphrey@gmail.co.uk
No comments:
Post a Comment