Pragmatism in the real world

ZF2 validator message keys

In Zend Framework 2, if you define your input filter via configuration, then you can override validation messages using a format along the lines of:

<validators>
    <notEmpty>
        <messages>
            <isEmpty>Please provide your telephone number</isEmpty>
        </messages>
    </notEmpty>
</validators>

Setting the message is easy enough, once you have the correct key name. This is a list of all the keys for the standard validators:

Validator Key name Default message
Alnum alnumInvalid Invalid type given. String, integer or float expected
Alnum notAlnum The input contains characters which are non alphabetic and no digits
Alnum alnumStringEmpty The input is an empty string
Alpha alphaInvalid Invalid type given. String expected
Alpha notAlpha The input contains non alphabetic characters
Alpha alphaStringEmpty The input is an empty string
Barcode barcodeInvalid Invalid type given. String expected
Barcode barcodeFailed The input failed checksum validation
Barcode barcodeInvalidChars The input contains invalid characters
Barcode barcodeInvalidLength The input should have a length of %length% characters
Between notBetween The input is not between ‘%min%’ and ‘%max%’, inclusively
Between notBetweenStrict The input is not strictly between ‘%min%’ and ‘%max%’
Bitwise notAnd The input has no common bit set with ‘%control%’
Bitwise notAndStrict The input doesn’t have the same bits set as ‘%control%’
Bitwise notXor The input has common bit set with ‘%control%’
Callback callbackInvalid An exception has been raised within the callback
Callback callbackValue The input is not valid
CreditCard creditcardChecksum The input seems to contain an invalid checksum
CreditCard creditcardContent The input must contain only digits
CreditCard creditcardInvalid Invalid type given. String expected
CreditCard creditcardLength The input contains an invalid amount of digits
CreditCard creditcardPrefix The input is not from an allowed institute
CreditCard creditcardService The input seems to be an invalid credit card number
CreditCard creditcardServiceFailure An exception has been raised while validating the input
Csrf notSame The form submitted did not originate from the expected site
Date dateInvalid Invalid type given. String, integer, array or DateTime expected
Date dateInvalidDate The input does not appear to be a valid date
Date dateFalseFormat The input does not fit the date format ‘%format%’
DateStep dateInvalid Invalid type given. String, integer, array or DateTime expected
DateStep dateInvalidDate The input does not appear to be a valid date
DateStep dateFalseFormat The input does not fit the date format ‘%format%’
DateStep dateStepNotStep The input is not a valid step
DateTime datetimeInvalid Invalid type given. String expected
DateTime datetimeInvalidDateTime The input does not appear to be a valid datetime
Digits notDigits The input must contain only digits
Digits digitsStringEmpty The input is an empty string
Digits digitsInvalid Invalid type given. String, integer or float expected
EmailAddress emailAddressInvalid Invalid type given. String expected
EmailAddress emailAddressInvalidFormat The input is not a valid email address. Use the basic format local-part@hostname
EmailAddress emailAddressInvalidHostname ‘%hostname%’ is not a valid hostname for the email address
EmailAddress emailAddressInvalidMxRecord ‘%hostname%’ does not appear to have any valid MX or A records for the email address
EmailAddress emailAddressInvalidSegment ‘%hostname%’ is not in a routable network segment. The email address should not be resolved from public network
EmailAddress emailAddressDotAtom ‘%localPart%’ can not be matched against dot-atom format
EmailAddress emailAddressQuotedString ‘%localPart%’ can not be matched against quoted-string format
EmailAddress emailAddressInvalidLocalPart ‘%localPart%’ is not a valid local part for the email address
EmailAddress emailAddressLengthExceeded The input exceeds the allowed length
Explode explodeInvalid Invalid type given
Float floatInvalid Invalid type given. String, integer or float expected
(Deprecated from ZF 2.4)
Float notFloat The input does not appear to be a float
(Deprecated from ZF 2.4)
GreaterThan notGreaterThan The input is not greater than ‘%min%’
GreaterThan notGreaterThanInclusive The input is not greater or equal than ‘%min%’
Hex hexInvalid Invalid type given. String expected
Hex notHex The input contains non-hexadecimal characters
Hostname hostnameCannotDecodePunycode The input appears to be a DNS hostname but the given punycode notation cannot be decoded
Hostname hostnameInvalid Invalid type given. String expected
Hostname hostnameDashCharacter The input appears to be a DNS hostname but contains a dash in an invalid position
Hostname hostnameInvalidHostname The input does not match the expected structure for a DNS hostname
Hostname hostnameInvalidHostnameSchema The input appears to be a DNS hostname but cannot match against hostname schema for TLD ‘%tld%’
Hostname hostnameInvalidLocalName The input does not appear to be a valid local network name
Hostname hostnameInvalidUri The input does not appear to be a valid URI hostname
Hostname hostnameIpAddressNotAllowed The input appears to be an IP address, but IP addresses are not allowed
Hostname hostnameLocalNameNotAllowed The input appears to be a local network name but local network names are not allowed
Hostname hostnameUndecipherableTld The input appears to be a DNS hostname but cannot extract TLD part
Hostname hostnameUnknownTld The input appears to be a DNS hostname but cannot match TLD against known list
Iban ibanNotSupported Unknown country within the IBAN
Iban ibanSepaNotSupported Countries outside the Single Euro Payments Area (SEPA) are not supported
Iban ibanFalseFormat The input has a false IBAN format
Iban ibanCheckFailed The input has failed the IBAN check
Identical notSame The two given tokens do not match
Identical missingToken No token was provided to match against
InArray notInArray The input was not found in the haystack
Int intInvalid Invalid type given. String or integer expected
(Deprecated from ZF 2.4)
Int notInt The input does not appear to be an integer
(Deprecated from ZF 2.4)
Ip ipInvalid Invalid type given. String expected
Ip notIpAddress The input does not appear to be a valid IP address
Isbn isbnInvalid Invalid type given. String or integer expected
Isbn isbnNoIsbn The input is not a valid ISBN number
IsInstanceOf notInstanceOf The input is not an instance of ‘%className%’
IsFloat floatInvalid Invalid type given. String, integer or float expected
(From ZF 2.4)
IsFloat notFloat The input does not appear to be a float
(From ZF 2.4)
IsInt intInvalid Invalid type given. String or integer expected
(From ZF 2.4)
IsInt notInt The input does not appear to be an integer
(From ZF 2.4)
LessThan notLessThan The input is not less than ‘%max%’
LessThan notLessThanInclusive The input is not less or equal than ‘%max%’
NotEmpty notEmptyInvalid Value is required and can’t be empty
NotEmpty isEmpty Invalid type given. String, integer, float, boolean or array expected
PhoneNumber phoneNumberNoMatch The input does not match a phone number format
PhoneNumber phoneNumberUnsupported The country provided is currently unsupported
PhoneNumber phoneNumberInvalid Invalid type given. String expected
PostCode postcodeInvalid Invalid type given. String or integer expected
PostCode postcodeNoMatch The input does not appear to be a postal code
PostCode postcodeService The input does not appear to be a postal code
PostCode postcodeServiceFailure An exception has been raised while validating the input
Regex regexInvalid Invalid type given. String, integer or float expected
Regex regexNotMatch The input does not match against pattern ‘%pattern%’
Regex regexErrorous There was an internal error while using the pattern ‘%pattern%’
Step typeInvalid Invalid value given. Scalar expected
Step stepInvalid The input is not a valid step
StringLength stringLengthInvalid Invalid type given. String expected
StringLength stringLengthTooShort The input is less than %min% characters long
StringLength stringLengthTooLong The input is more than %max% characters long
Uri uriInvalid Invalid type given. String expected
Uri notUri The input does not appear to be a valid Uri

4 thoughts on “ZF2 validator message keys

  1. It is useful to know that you can also set one message for all the validation failure cases of some validator. For example, if one wants to display "Email is not valid message" every time EmailAddress validation fails, this is how validator should be configured:

     <validators>
       <emailAddress>
         <message>Email is not valid message</message>
       </emailAddress>
     </validators>
    

    Note that message option is used for this purpose.

  2. I wonder why i can't find this list in the official ZF2 manual. WHY they must have a so baddly documented manual?!

Comments are closed.