Friday, February 4, 2011

Re: Charfield, limiting acceptable characters


On Feb 4, 2011, at 2:47 PM, ozgur yilmaz wrote:

It was possible in the past with validator_list. Like:

regex = r'^[A-z][\w-]{2,31}$'
name = models.CharField(max_length=32, unique=True , validator_list=[validators.MatchesRegularExpression(regex)] )

But with what code to override the clean method? Is there any sample or built in function for this purpose?

If your field is named name, then you add a function to your form called clean_name and put whatever you want in it.


Shawn

No comments:

Post a Comment