Regex is done via a custom validator. works pretty simple. here is an
example how i use to check if the entered data is a correct UK
postcode (zip code)

from django.core import validators

you might need to import some thing else as well (import datetime,
random, sha, re, os, Image, urllib thats all i use in this app)

class Property(models.Model):
        def isValidUKPostcode(self, field_data):
                p = re.compile(r'^(GIR 
0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HIK-Y][0-9](|
[0-9]|[ABEHMNPRVWXY]))|[0-9][A-HJKSTUW]) [0-9][ABD-HJLNP-UW-Z]{2})$')
                if not p.match(field_data['postcode']):
                        raise validators.ValidationError("You have to have a 
space in the
Postcode and all Capital letters.")

        def isValidReferenceID0(self, field_data):
                p = re.compile(r'(^[\w-]*$)')
                if not (p.match(field_data['referenceID0'])):
                        raise validators.ValidationError("The Reference you 
entered is not
Valid.")

These are 2 regex i use in my model to check if the post code is
correct and if the refereceID0 field is correct.

        referenceID0 = models.CharField(maxlength=10,
validator_list=[isValidReferenceID0], unique=True,
verbose_name="Reference ID")
        postcode = models.CharField(maxlength=10,
validator_list=[isValidUKPostcode], verbose_name="Post Code",
help_text="Has to be in Capital letters and contain a space.")

these are the fields in the model.
I am not very good in regex and found this tool quite helpful
regexCreator_v0_85 (google for it) a java regex builder.

works pretty well in the standard admin.
hope it helps.

o

On Oct 10, 7:40 am, Nader <[EMAIL PROTECTED]> wrote:
> Hello
>
> I use Django  0.96 and in one of model's field I have to define a
> 'path' entry in which een Unix path (/usr/people/...)  can be given as
> an input with validation naturally.
> I would like to use Admin interface and have not found any Built-in
> Filed of "RegexField" class to use it.
>
> cla  ss MyModel(...):
>    password = modles.RegexField()
>
> I can't do it because we don't have any "RegexField" attribute in
> "Admin" class. I have
> been looking for information about this problem and have not found any
> solution.
> Could you tell me how I can solve this problem?
>
> Regards,
> Nader


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to