Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions reference/constraints/Issn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
Issn
====

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about adding a link to Wikipedia or similar to get more information on what an ISSN actually is? (similar to what is done in Luhn constraint)?

.. versionadded:: 2.3
The ISSN validation is new in Symfony 2.3.

Validates that a value is a valid `ISSN`_.

+----------------+-----------------------------------------------------------------------+
| Applies to | :ref:`property or method<validation-property-target>` |
+----------------+-----------------------------------------------------------------------+
| Options | - `message`_ |
| | - `caseSensitive`_ |
| | - `requireHyphen`_ |
+----------------+-----------------------------------------------------------------------+
| Class | :class:`Symfony\\Component\\Validator\\Constraints\\Issn` |
+----------------+-----------------------------------------------------------------------+
| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\IssnValidator` |
+----------------+-----------------------------------------------------------------------+

Basic Usage
-----------

.. configuration-block::

.. code-block:: yaml

# src/JournalBundle/Resources/config/validation.yml
Acme\JournalBundle\Entity\Journal:
properties:
issn:
- Issn: ~

.. code-block:: php-annotations

// src/Acme/JournalBundle/Entity/Journal.php
namespace Acme\JournalBundle\Entity;

use Symfony\Component\Validator\Constraints as Assert;

class Journal
{
/**
* @Assert\Issn
*/
protected $issn;
}

.. code-block:: xml

<!-- src/Acme/JournalBundle/Resources/config/validation.xml -->
<class name="Acme\JournalBundle\Entity\Journal">
<property name="issn">
<constraint name="Issn" />
</property>
</class>

.. code-block:: php

// src/Acme/JournalBundle/Entity/Journal.php
namespace Acme\JournalBundle\Entity;

use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints as Assert;

class Journal
{
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('issn', new Assert\Issn());
}
}

Options
-------

message
~~~~~~~

**type**: ``String`` default: ``This value is not a valid ISSN.``

The message shown if the given value is not a valid ISSN.

caseSensitive
~~~~~~~~~~~~~

**type**: ``Boolean`` default: ``false``

The validator will allow ISSN values to end with a lower case 'x' by default.
When switching this to ``true``, the validator requires an upper case 'X'.

requireHyphen
~~~~~~~~~~~~~

**type**: ``Boolean`` default: ``false``

The validator will allow non hyphenated ISSN values by default. When switching
this to ``true``, the validator requires an hyphenathed ISSN value.

.. _`ISSN`: http://en.wikipedia.org/wiki/Issn
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a new line after the last line to avoid bad diffs if someone adds another link in this article

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!


1 change: 1 addition & 0 deletions reference/constraints/map.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ Other Constraints
* :doc:`All </reference/constraints/All>`
* :doc:`UserPassword </reference/constraints/UserPassword>`
* :doc:`Valid </reference/constraints/Valid>`
* :doc:`Issn </reference/constraints/Issn>`