Archived
Validate input data.
This commit is contained in:
1 parent
b4372fc341
commit
1c8c3beb8c
3 files changed
+16
-5
No files matched your search
@@ -8,6 +8,8 @@ from django.views.generic import TemplateView
|
||||
from settings import TRELLO_API_KEY, TRELLO_TOKEN
|
||||
from lib import trello
|
||||
|
||||
import utils
|
||||
|
||||
class BaseFormView(TemplateView):
|
||||
template_name = None
|
||||
trello_board_id = None
|
||||
@@ -48,8 +50,8 @@ class BaseFormView(TemplateView):
|
||||
'client_error' : params['client'] == '',
|
||||
'deadline_error' : params['deadline'] == '',
|
||||
'contact_name_error' : params['contact_name'] == '',
|
||||
'contact_email_error' : params['contact_email'] == '',
|
||||
'contact_number_error' : False,
|
||||
'contact_email_error' : not utils.is_email_valid(params['contact_email']),
|
||||
'contact_number_error' : not utils.is_phone_valid(params['contact_number']),
|
||||
}
|
||||
|
||||
def _get_order_url(self, request, order):
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import re
|
||||
|
||||
def is_phone_valid(phone_str):
|
||||
pattern = re.compile('^(\+\d{2,4})?\s*(\s?\d){6,}$')
|
||||
return pattern.match(phone_str) is not None
|
||||
|
||||
def is_email_valid(email_str):
|
||||
pattern = re.compile('^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$')
|
||||
return pattern.match(email_str) is not None
|
||||
@@ -29,10 +29,10 @@
|
||||
<div class="formitem">
|
||||
<legend>Forening</legend>
|
||||
<label>Hvem bestiller?</label>
|
||||
<input type="text" name="client" value="{{ client }}" />
|
||||
{% if errors.client_error %}
|
||||
<label class="text-error">Feltet er obligatorisk.</label>
|
||||
{% endif %}
|
||||
<input type="text" name="client" value="{{ client }}" />
|
||||
</div>
|
||||
|
||||
<div class="formitem">
|
||||
@@ -62,7 +62,7 @@
|
||||
<div class="controls">
|
||||
<input type="text" name="contact_email" value="{{ contact_email }}" />
|
||||
{% if errors.contact_email_error %}
|
||||
<label class="text-error">Feltet er obligatorisk.</label>
|
||||
<label class="text-error">Skriv inn gyldig epost-adresse.</label>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
@@ -71,7 +71,7 @@
|
||||
<div class="controls">
|
||||
<input type="text" name="contact_number" value="{{ contact_number }}" />
|
||||
{% if errors.contact_number_error %}
|
||||
<label class="text-error">Feltet er obligatorisk.</label>
|
||||
<label class="text-error">Skriv inn gyldig telefonnummer.</label>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user