Yes.

you can do:

import re
from gluon.validator import Validator
class CANADIAN_ZIP(Validator):
    regex = re.compile('^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} 
*\d{1}[A-Z]{1}\d{1}$')
    def __init__(self,error_message='invalid!):
         self.error_message = error_message
    def __call__(self,value):
         value = str(value).upper()
         if self.regex.match(value): return value, None
         else: return value, self.error_message

then use requires=CANADIAN_ZIP()

On Wednesday, 26 September 2012 14:21:07 UTC-5, Richard wrote:
>
> You can may use .capitalize() before the vars get validated by validators. 
> I thought that there was a way to do action before the form get validated, 
> but I can't find in the book, something like beforevalidation, instead of 
> onvalidation that is provided.
>
> I think that if beforevalidation doesn't exist it could be helpful 
> sometimes, but in this case you can just make your own validator that could 
> be base on IS_MATCH() and only .capitalize() variable before it get into 
> IS_MATCH()
>
> Richard
>
> On Wed, Sep 26, 2012 at 7:29 AM, Le Don X <[email protected]<javascript:>
> > wrote:
>
>> don't be sorry for jumping in .... it is appreciated ! .. and refreshing 
>> to noticed that there are canadian folks like me on here ! 
>>
>> to resume ... from all the responses received - the best canadian postal 
>> code validation is actually the one submitted by Adnan :
>>
>> this one :  ^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$
>>
>> thank you ! ...
>>
>> with just one addition : the postal code entered will need to be 
>> capitalised before validation to avoid any issues !
>>
>> This thread could help others with the same concern !
>>  
>> -- 
>>  
>>  
>>  
>>
>
>  

-- 



Reply via email to