Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 227903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:38:15+00:00 2026-05-11T19:38:15+00:00

from django import forms class ActonForm(forms.Form): creator = forms.RegexField(‘^[a-zA-Z0-9\-‘ ]$’,max_length=30, min_length=3) data = {‘creator’:

  • 0
from django import forms
class ActonForm(forms.Form):
    creator = forms.RegexField('^[a-zA-Z0-9\-' ]$',max_length=30, min_length=3)

data = {'creator': 'hello'
        }
f = ActonForm(data)
print f.is_valid()

Why doesn’t this work? have i made a wrong regular expression? I wanted a name field with provision for single quotes and a hyphen

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T19:38:15+00:00Added an answer on May 11, 2026 at 7:38 pm

    It kind of shows in the syntax highlighting. The apostrophe in the regex isn’t escaped, it should be like this:

    forms.RegexField('^[a-zA-Z0-9\\-\' ]$',max_length=30, min_length=3)
    

    Edit: When escaping things in the regular expression, you need double backslashes. I doubled the backslash before the hyphen (not that it has to be escaped in this particular case.)

    Secondly, your regular expression only allows for a single character. You need to use a quantifier. + means one or more, * means 0 or more, {2,} means two or more, {3,6} means three to six. You probably want this:

    forms.RegexField('^[a-zA-Z0-9\\-\' ]+$',max_length=30, min_length=3)
    

    Do take care that the above regular expression will allow spaces in the start and end of the field as well. To avoid that you need a more complex regex.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given: from django.db import models class Food(models.Model): Food, by name. name = models.CharField(max_length=25) class
Given a class: from django.db import models class Person(models.Model): name = models.CharField(max_length=20) Is it
How can i clean and modify data from a form in django. I would
I've got a couple django models that look like this: from django.contrib.sites.models import Site
What is the best idea to fill up data into a Django model from
In Django, given excerpts from an application animals likeso: A animals/models.py with: from django.db
I am writing an application where I will be accessing the database from django
I need to perform a filtered query from within a django template, to get
Coming from a background in Django, I often use template inheritance, where multiple templates
I am building a relatively simple Django application and apart from the main page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.