Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.1.0

Request #16906 no email validation like HTML_QuickForm_Rule_Email
Submitted: 2009-12-15 16:27 UTC
From: hm2k Assigned: mansion
Status: Assigned Package: HTML_QuickForm2 (version 0.3.0)
PHP Version: Irrelevant OS:
Roadmaps: 2.1.0    
Subscription  


 [2009-12-15 16:27 UTC] hm2k (James Wade)
Description: ------------ HTML_QuickForm had email validation HTML_QuickForm2 does not, any reason?

Comments

 [2010-07-09 13:50 UTC] cweiske (Christian Weiske)
One could easily use PHP's filter method to check if a string is a valid email: > function isValidEmail($email) { > return filter_var($email, FILTER_VALIDATE_EMAIL) !== false; > } That would need to be combined with a callback. But yes, it'd be cool if that rule would exist in HTML_QuickForm2 by default since it's a common usecase.
 [2010-07-09 14:10 UTC] hm2k (James Wade)
It would make sense, especially as previously PHP used to base it's FILTER_VALIDATE_EMAIL on HTML_QuickForm's regex. Where once HTML_QuickForm was leading the way, HTML_QuickForm2 has not filled that gap. Let's see it return.
 [2010-07-09 14:30 UTC] mansion (Bertrand Mansion)
We could also add a new rule simply called 'filter_var' or 'filter' that would in turn call the function filter_var() with given parameters ? It would make things easier than using the callback rule. The filter extension is apparently enabled by default since PHP 5.2, which is our minimum version for using QF2 so it should be ok. The filter_var email regex is a bit difficult to read and will validate addresses with IPv4 or IPv6 in place of domain names which might not always be what you expect. At the moment, I use this regex instead : "/^[_+a-z0-9-]+(\.[_+a-z0-9-']+)*@[a-z0-9-]+(\.[a-z0-9-]{1,})*\.([a- z]{2,}){1}$/" It's not perfect but it fits my needs.
 [2010-07-09 15:02 UTC] hm2k (James Wade)
I wrote a whole essay on this matter: http://www.hm2k.com/posts/what-is-a-valid-email-address It pretty much addresses my concerns here.
 [2010-07-09 19:08 UTC] cweiske (Christian Weiske)
While the filter_var rule is a good idea itself, is it not something I would advise people to use for validating email addresses with QF2 - it's a common task that requires an own rule IMO.
 [2010-07-09 20:45 UTC] hm2k (James Wade)
My advise would be to impliment it from HTML_QuickForm and improve. Implementing filter_var, while better than nothing isn't exactly ideal.
 [2011-11-21 13:53 UTC] mansion (Bertrand Mansion)
-Assigned To: +Assigned To: mansion
 [2012-03-20 20:26 UTC] avb (Alexey Borzov)
-Summary: no email validation like HTML_Qu +Summary: no email validation like HTML_QuickForm_Rule_Email
Email rule is available in 2.0.0beta1 However it is quite basic and needs a few knobs added to configure its behaviour.