Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

using regex validators in django models

from django.core.validators import RegexValidator
from django.db import models
PHONE_NUMBER_REGEX = RegexValidator(r'^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-s./0-9]*$', 'only valid email is required')
class SomeClass(models.Model):
  phone =  models.CharField(max_length=14, validators=[PHONE_REGEX])
  
Comment

django regexvalidator example

# for outside model uses
from django.core.validators import RegexValidator

validate_alphanumeric = RegexValidator(r'^[a-zA-Z0-9]*$', 'Only alphanumeric characters are allowed.')
validate_alphanumeric("foo") # ok, nothing happens
validate_alphanumeric("++") # raises a ValidationError

ValidationError: [u'Only alphanumeric characters are allowed.']
Comment

PREVIOUS NEXT
Code Example
Python :: catch error data with except python 
Python :: text widget get tkinter 
Python :: how to make a column a factor in pandas 
Python :: python how to count items in array 
Python :: pandas change column dtype 
Python :: how to write and read dictionary to a file in python 
Python :: python find string 
Python :: python substring in string 
Python :: flask debugtoolbar 
Python :: breadth first search graph python 
Python :: How to convert string date to datetime format in python 
Python :: python pandas convert series to percent 
Python :: display data from database in django 
Python :: how to set variable in flask 
Python :: int to ascii python 
Python :: how to map longitude and latitude in python 
Python :: isdigit python 
Python :: python zip folder 
Python :: django serialize foreign key, django serializer foreign key 
Python :: python get value from dictionary 
Python :: turn off warning when import python 
Python :: how to add textbox in pygame window 
Python :: underscore in python 
Python :: discord.py send image from url 
Python :: how to change frame in tkinter 
Python :: python check if there is internet connection 
Python :: escape character in python 
Python :: pyqt button clicked connect 
Python :: python to executable windows 
Python :: python get zip file size 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =