johnfk3 johnfk3 - 12 days ago 7
Python Question

WTForms doesn't validate MAC address

I'm using WTForms'

MacAddress
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():
print form.choice.data
return redirect(url_for('editdevice'))
else:
print form.errors

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


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

Answer

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)

Comments