You can't provide multiple regex's to the RegexField. What you were doing
before is exactly equivalent to this:

r'^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!$%^&*?@#-_+=]).*$'

So for my suggestion, just do this:

regex_f=r'^.*(?=.{{{MIN},{MAX}}})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!$%^&*?@#-_+=]).*$'

But the "^.*" and the ".*$" are not needed since RegexField uses
RegexValidator, which uses re.search().

On Thu, May 19, 2016 at 1:53 AM, Arun S <arun....@gmail.com> wrote:

> I Did try this, i think i am not doing it right:
> Could you tell what is that i am doing is wrong.
> I am now not able to provide multiple Regex in the forms.RegexField using
> the above method.
>
>
>
> regex_f=r'^.*(?=.{{{MIN},{MAX}}})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!$%^&*?@#-_+=])'
>      old_password = forms.RegexField(
>           label='Old Password',
>           widget=ShowPasswordWidget(),
>
> *regex = regex_f.format(MIN=settings.PASSWORD_MIN_LEN,
> MAX=settings.PASSWORD_MAX_LEN)                       r'.*$',*
>           error_messages={'invalid' : 'Password must contain at least 8
> characters'
>           ' with one upper case letter, one lower case letter,'
>           ' one number (0-9) and one special character (!$%^&*?@#-_+=)'})
>
> Previously i was using this as:
> -----
>    old_password = forms.RegexField(
>         label='Old Password',
>         widget=ShowPasswordWidget(),
>
>
> *
> regex=r'^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!$%^&*?@#-_+=])'
>                r'.*$', *        error_messages={'invalid' : 'Password
> must contain at least 8 characters'
>          ' with one upper case letter, one lower case letter,'
>          ' one number (0-9) and one special character (!$%^&*?@#-_+=)'})
>
> On Thursday, May 19, 2016 at 11:26:58 AM UTC+5:30, Stephen Butler wrote:
>>
>> I think I'd just use format() on the regex, being careful to escape '{'
>> and '}':
>>
>> regex_f=r'^.*(?=.*{{{MIN},{MAX}}}*)(?=.*\d)(?
>> =.*[a-z])(?=.*[A-Z])(?=.*[!$%^&*?@#-_+=])'
>> regex=regex_f.format(MIN=settings.MY_RE_MIN, MAX=settings.MY_RE_MAX)
>>
>>
>> On Thu, May 19, 2016 at 12:37 AM, Arun S <arun...@gmail.com> wrote:
>>
>>> Hi,
>>>
>>> I have a Regular Expression something like this:
>>> regex=r'^.*(?=.*{8,}*
>>> )(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!$%^&*?@#-_+=])'
>>>                r'.*$',
>>>
>>> In this, i would like to read the values from the Django Setting file on
>>> the Max and Min Length and provide them as my input instead of Hard Coding.
>>>
>>> How can a Variable be provided/escaped in a regex.
>>> Can some one throw some light on this ?
>>>
>>> Cheers
>>> Arun
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/90556052-063e-4307-b095-c37a9920399b%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/90556052-063e-4307-b095-c37a9920399b%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/2f010f88-0824-4f92-91c6-ccf9333d7dab%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/2f010f88-0824-4f92-91c6-ccf9333d7dab%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD4ANxUBwYu-fKVyDJARLaAqvy4PiXwV6x20owO2VQATfOxrSg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to