Skip to content

Commit

Permalink
Brought implementaton up to date with Django trunk
Browse files Browse the repository at this point in the history
- Added inverseMatch option for RegexValidator
  - Backwards-incompatible change: now takes a kwargs object
- Added whitelisting of schemes to URLValidator
  - Now takes a kwargs object
- Added whitelisting of domains to EmailValidator
  - Backwards-incompatible change: now takes a kwargs object
- Email parts are now validated individually
- Backwards-incompatible change: removed the pre-configured URLValidator instance, validateURL
- Some linting cleanup
- Added more tests from the Django test suite
  • Loading branch information
insin committed Feb 19, 2014
1 parent aaed47d commit 926c986
Show file tree
Hide file tree
Showing 5 changed files with 264 additions and 131 deletions.
26 changes: 22 additions & 4 deletions CHANGES.rst
@@ -1,17 +1,35 @@
0.1.0
=====

* **Backwards-incompatible change** -- RegexValidator and EmailValidator now
take a configuration object as their only argument, rather than individual
configuration arguments.

* **Backwards-incompatible change** -- removed the pre-configured URLValidator
instance, validateURL.

* Added an inverseMatch option for RegexValidator.

* Added a whitelist option for EmailValidator, for specifying whitelisted
domains.

* Added a schemes option for URLValidator, which now takes a onfiguration object
argument.

0.0.3 / 2012-06-29
==================

* Updated to isomorph 0.2
* Updated to isomorph 0.2.

0.0.2 / 2012-03-08
==================

* Fixed overwriting of url module variable after validating an IDNA domain
* Fixed overwriting of url module variable after validating an IDNA domain.

0.0.1 / 2012-03-08
==================

* Added validateURL, since URLValidator no longer takes configuration params
* Extracted validators from `newforms`_ for reuse across projects
* Added validateURL, since URLValidator no longer takes configuration params.
* Extracted validators from `newforms`_ for reuse across projects.

.. _`newforms`: https://github.com/insin/newforms
47 changes: 33 additions & 14 deletions README.rst
Expand Up @@ -5,7 +5,8 @@ Validators |travis_status|
.. |travis_status| image:: https://secure.travis-ci.org/insin/validators.png
:target: http://travis-ci.org/insin/validators

Validators which can be shared between browsers and `Node.js`_.
Validators which can be shared between browsers and `Node.js`_, based on Django's
core validators.

Validators are either Functions or Objects with a ``__call__()`` function, which
take a value and throw a ``ValidationError`` if they detect that it is invalid.
Expand Down Expand Up @@ -33,8 +34,8 @@ Error
Validation error constructor.

For customisation purposes, in addition to a validation message, a
ValidationError may specify a ``code`` to itentify the category of error and any
``params`` which were inserted into the validation message, when applicable.
``ValidationError`` may specify a ``code`` to itentify the category of error and
any ``params`` which were inserted into the validation message, when applicable.

Utilities
=========
Expand Down Expand Up @@ -70,27 +71,45 @@ defined.
Validators
==========

``RegexValidator(regex, message, code)``
----------------------------------------
``RegexValidator(options)``
---------------------------

Creates a validator which walidates that input matches a regular expression.

``URLValidator()``
--------------------------
Options which can be passed are:

* ``regex`` -- the regular expression pattern to search for the provided value,
or a pre-compiled ``RegExp``. By default, matches any string (including an
empty string)
* ``message`` -- the error message used by ``ValidationError`` if validation
fails. Defaults to ``"Enter a valid value"``.
* ``code`` -- the error code used by ``ValidationError`` if validation fails.
Defaults to ``"invalid"``.
* ``inverseMatch`` -- the match mode for ``regex``. Defaults to ``false``.

``URLValidator(options)``
-------------------------

Creates a validator which validates that input looks like a valid URL.

``EmailValidator(regex, message, code)``
----------------------------------------
Options which can be passed are:

* ``schemes`` -- allowed URL schemes. Defaults to
``['http', 'https', 'ftp', 'ftps']``.

``EmailValidator(options)``
---------------------------

Creates a validator which validates that input looks like a valid e-mail
address.

``validateURL(value)``
----------------------
Options which can be passed are:

Validates that input looks like a valid URL -- this is a preconfigured instance
of a ``URLValidator``,
* ``message`` -- error message to be used in any generated ``ValidationError``.
* ``code`` -- error code to be used in any generated ``ValidationError``.
* ``whitelist`` -- a whitelist of domains which are allowed to be the only thing
to the right of the ``@`` in a valid email address -- defaults to
``['localhost']``.

``validateEmail(value)``
------------------------
Expand Down Expand Up @@ -176,7 +195,7 @@ If an invalid address is passed, a ``ValidationError`` is thrown.
MIT License
===========

Copyright (c) 2012, Jonathan Buchanan
Copyright (c) 2014, Jonathan Buchanan

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down

0 comments on commit 926c986

Please sign in to comment.