-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforms.py
More file actions
29 lines (22 loc) · 850 Bytes
/
forms.py
File metadata and controls
29 lines (22 loc) · 850 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import re
from wtforms import Form, StringField, validators, TextField
from utils import twilio_authenticate
class ReminderForm(Form):
phone = StringField('Phone', [
validators.Length(
min=13, max=13, message='Enter a valid phone number')
])
message = TextField('Message', [validators.Length(max=100)])
@staticmethod
def validate_phone(field):
rule = re.compile(r'(^[+0-9]{1,3})*([0-9]{10,11}$)')
if not rule.search(field.data):
return False
client = twilio_authenticate()
if field.data not in [
i.phone_number for i in client.outgoing_caller_ids.list()
]:
raise validators.ValidationError(
"Your phone nubmer is not verified\
. Contact admin to add your phone number.")
return True