I have form with field:
name = forms.RegexField(regex=r'\w+$', label=u'Name', required=True)
but if I type special chars (ś for example) form not pass is_valid() function. How to do it?
RegexBuddy's regex engine is fully Unicode-based starting with version 2.0. 0.
The regular expression \s is a predefined character class. It indicates a single whitespace character. Let's review the set of whitespace characters: [ \t\n\x0B\f\r]
Inside a character range, \b represents the backspace character, for compatibility with Python's string literals. Matches the empty string, but only when it is not at the beginning or end of a word.
Activate Unicode matching for \w
.
name = forms.RegexField(regex=r'(?u)\w+$', label=u'Name', required=True)
Instead of defining the regex as a string, you can compile it to a regex object first, setting the re.U flag:
import re
name_regex = re.compile(r'\w+$', re.U)
name = forms.RegexField(regex=name_regex, label=u'Name', required=True)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With