johnfk3 johnfk3 - 1 month ago 21
Python Question

WTForms doesn't validate MAC address

I'm using WTForms'

validator, but it doesn't recognize valid MAC addresses that I enter. Why isn't it working?

{'choice': [u'Invalid Mac address.']}

class EditForm(Form):
choice = TextField('choice', validators=[DataRequired(), MacAddress()])

@app.route('/', methods=['GET', 'POST'])
def devicechoice():
form = EditForm()

if form.validate_on_submit():
return redirect(url_for('editdevice'))
print form.errors

return render_template('devicechoice.html', form=form)

<form action="" method="post">
{{ form.hidden_tag() }}
{{ form.choice() }}
<input type="submit">


Question has been answered by @Ketouem, Simply putting a ":" after every 2 characters of the Mac address validates the form. (12:34:56:78:AB:CD)