Skip to content

Commit

Permalink
Merge pull request #266 from philippefaes/exact-length
Browse files Browse the repository at this point in the history
  • Loading branch information
ftm committed Jun 12, 2018
2 parents 18436c8 + a020e97 commit 17d2309
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def test_length(self):
self.assertEqual(length(min=6)(self.form, field), None)
self.assertRaises(ValidationError, length(max=5), self.form, field)
self.assertEqual(length(max=6)(self.form, field), None)
self.assertEqual(length(min=6,max=6)(self.form, field), None)

self.assertRaises(AssertionError, length)
self.assertRaises(AssertionError, length, min=5, max=2)
Expand All @@ -111,6 +112,7 @@ def test_length(self):
self.assertTrue('at least 8' in grab(min=8))
self.assertTrue('longer than 5' in grab(max=5))
self.assertTrue('between 2 and 5' in grab(min=2, max=5))
self.assertTrue('exactly 5' in grab(min=5, max=5))

def test_required(self):
self.assertEqual(data_required()(self.form, DummyField('foobar')), None)
Expand Down
3 changes: 3 additions & 0 deletions wtforms/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ def __call__(self, form, field):
elif self.min == -1:
message = field.ngettext('Field cannot be longer than %(max)d character.',
'Field cannot be longer than %(max)d characters.', self.max)
elif self.min == self.max:
message = field.ngettext('Field must be exactly %(max)d character long.',
'Field must be exactly %(max)d characters long.', self.max)
else:
message = field.gettext('Field must be between %(min)d and %(max)d characters long.')

Expand Down

0 comments on commit 17d2309

Please sign in to comment.