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 :: sort python dictionary by date 
Python :: get self file name in python 
Python :: center buttons tkinter 
Python :: django foreign key field on delete do nothing 
Python :: python get int from string 
Python :: install python 3.6 mac brew 
Python :: python datetime yesterday 
Python :: install postgres for python mac 
Python :: python print os platform 
Python :: select python version ubuntu 
Python :: godot code for movement for topdown game 
Python :: how to extract month from date in python 
Python :: mouse in pygame 
Python :: how to order ints from greatest to least python 
Python :: create pyspark session with hive support 
Python :: change dataframe column type 
Python :: django queryset average of unique values 
Python :: flask getting started 
Python :: pandas ttable with sum totals 
Python :: stop server django programmatically 
Python :: normalize column pandas 
Python :: how to stop the program in python 
Python :: link python3 to python3.7 
Python :: django serializer exclude fields 
Python :: square (n) sum 
Python :: procfile flask 
Python :: if none in column remove row 
Python :: py random list integers 
Python :: is string python 
Python :: sqlite3 like python 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =