johnfk3 johnfk3 - 1 year ago 117
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">

Answer Source

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)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download