Installations
npm install redux-form-validators
Releases
Unable to fetch releases
Developer
gtournie
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
No
Node Version
10.15.0
NPM Version
6.9.0
Statistics
152 Stars
65 Commits
22 Forks
3 Watching
14 Branches
8 Contributors
Updated on 29 Sept 2024
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
3,505,376
Last day
30.3%
2,424
Compared to previous day
Last week
10.4%
10,722
Compared to previous week
Last month
76.9%
39,154
Compared to previous month
Last year
-24.2%
439,043
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
3
Dev Dependencies
54
redux-form-validators
Simple validations with redux-form / react-final-form. Heavily inspired by the rails validations.
Installation | Demo | Documentation | ☕️Send some love ❤️
Installation
npm install redux-form-validators
Note: For internationalization purposes, this package is compatible with react-intl.
Demo
Live demo -> FieldLevelValidationForm.js
Or you can also run the example project. Just clone the repo, run npm i -d && npm start
and then go to http://localhost:3003/
How to use
If you're already familiar with redux-form it should be pretty straight forward:
Field validation
This example shows you how to set a field level validation with redux-form.
Thanks to redux-form-validators
, you'll only have to pass the validators needed:
1import { required, email } from 'redux-form-validators' 2 3<Field name="email" type="email" label="Email" 4 component={renderField} validate={[required(), email()]} />
That's it! =)
Sync validation
Now let's replace the validate function of this redux-form example:
1const validate = validateForm({ 2 username: [required(), length({ max: 15 })], 3 email: [required(), email()], 4 age: [ 5 required(), 6 numericality({ 7 int: true, 8 '>=': 18, 9 msg: { '>=': 'You must be at least 18 years old' }, 10 }), 11 ], 12})
Documentation
Validators
- required / presence
- numericality
- date
- length
- confirmation
- format
- acceptance
- inclusion
- exclusion
- absence
- url
- file
Form
More
- default options
- memoization
- i18n and react-intl
- default messages override
- common validation options
- conditional validation
- adding a validator
- date helpers
- url helper
required (alias: presence)
Validates that the specified value is not empty. It uses the trim()
method to check if the value is a blank string, that is, a string that is either empty or consists of whitespace.
1<Field name="login" type="text" label="Login" 2 component={renderField} validate={required()} />
The default error message is "is required". You can also pass custom message via the message option.
Validates that the specified value is a valid email address. It uses the email.REG_EMAIL
regexp to check the value.
1<Field name="email" type="email" label="Email" 2 component={renderField} validate={email()} />
This validator also provides 2 options to check (case insensitive) the domain:
domainWhitelist
- Specifies a list of domains alloweddomainBlacklist
- Specifies a list of domains not allowed
Examples
1email({ domainWhitelist: ['GOOGLE.COM', 'outlook.*'] }) 2email({ domainWhitelist: ['*.fr'] }) 3 4// Disposable email addresses 5email({ domainBlacklist: ['yopmail.com', 'guerrillamail.*'] })
The default error messages are:
- "is not a valid email"
- "{domain} is not an accepted domain"
numericality
Validates that your value have only numeric values. By default, it will match an optional sign followed by an integral or floating point number. To specify that only integral numbers are allowed set int
(or integer
) to true.
1<Field name="lat" type="text" label="Latitude" 2 component={renderField} validate={numericality()} />
Besides int
, this validator also accepts the following options to add constraints to acceptable values:
>
(orgreaterThan
) - Specifies the value must be greater than the supplied value. The default error message for this option is "must be greater than ${count}".>=
(orgreaterThanOrEqualTo
) - Specifies the value must be greater than or equal to the supplied value. The default error message for this option is "must be greater than or equal to ${count}".=
(orequalTo
) - Specifies the value must be equal to the supplied value. The default error message for this option is "must be equal to ${count}".!=
(orotherThan
) - Specifies the value must be other than the supplied value. The default error message for this option is "must be other than 4{count}".<
(orlessThan
) - Specifies the value must be less than the supplied value. The default error message for this option is "must be less than ${count}".<=
(orlessThanOrEqualTo
) - Specifies the value must be less than or equal to the supplied value. The default error message for this option is "must be less than or equal to ${count}".odd
- Specifies the value must be an odd number if set to true. The default error message for this option is "must be odd".even
- Specifies the value must be an even number if set to true. The default error message for this option is "must be even".
Examples
1numericality({ int: true }) 2numericality({ '>': 6 }) 3numericality({ '>': 6, '<=': 20 }) 4numericality({ int: true, odd: true })
The default error messages are:
- "is not a number"
- "must be greater than {number}"
- "must be greater than or equal to {number}"
- "must be equal to {number}"
- "must be other than {number}"
- "must be less than {number}"
- "must be less than or equal to {number}"
- "must be odd"
- "must be even"
date
Very simple date validator. Limited to year, month and day validation (but it should mostly match your needs). Feel free to use a date manipulation lib to write a better date validator (see add a validator).
1<Field name="date" type="text" label="Date" 2 component={renderField} validate={date({ format: 'mm/dd/yyyy' })} />
Accepts the following options:
format
- Specifies the format that should match the date string. Accepts only the current flags:y
,m
&d
. The number of flags used represents the number of digits expected (e.g.yyyy
expects 4 digits whileyy
expects 2). Format examples:mm/dd/yyyy
,dd/mm/yyyy
,yyyy-mm-dd
,mm/dd/yy
,yyyy/mm
,mm/dd
...ymd
- Allows you to customize the format, to be more readable in case you're using i18n. For instance, you could use{ format: 'jj/mm/aaaa', ymd: 'amj' }
for a French format.
(See default options to set format
and ymd
globally)
And the comparable options:
- '=', '>', '>=', '<', '<='. All of these options accept either a Date object, a timestamp, or a function (which returns a Date or a timestamp). To avoid syncing issues, don't pass
new Date()
directly but wrap it in a function or just pass the string'today'
. Note that these options are only available if these flags are present:y
+m
+d
ORy
+m
OR justy
)
Examples
1date({ format: 'mm/dd/yyyy' }) 2date({ format: 'mm/yyyy' }) 3date({ format: 'YYYY-MM-DD', ymd: 'YMD' }) 4date({ format: 'dd/mm/yyyy', '<': new Date(2020, 0, 1), '>=': new Date(1980, 0, 1) }) 5date({ format: 'mm/dd/yyyy', '>': 'today', msg: 'must be in the future' }) 6date({ format: 'mm/dd/yyyy', '<=': twentyYearsAgo, msg: 'you must be at least 20 years old' }) 7 8function twentyYearsAgo() { 9 let d = new Date() 10 d.setFullYear(d.getFullYear() - 20) 11 return d 12}
The default error messages are:
- "expected format: {format}"
- "is not a valid date" (e.g. Feb 29 2017)
- "should be {op} {date}" (e.g. 'should be > 01/14/2017')
See also parseDate & formatDate
length
Validates the length of the value. It provides a variety of options, so you can specify length constraints in different ways:
1<Field name="name" type="text" label="Name" 2 component={renderField} validate={length({ min: 2 })} />
The possible length constraint options are:
min
(orminimum
) - The value cannot have less than the specified length.max
(ormaximum
) - The value cannot have more than the specified length.in
(orwithin
) - The value length must be included in a given interval. The value for this option must be an array.is
(or=
) - The value length must be equal to the given value.
Examples
1length({ minimum: 2 }) 2length({ min: 2, max: 8 }) 3length({ in: [2, 8] }) 4length({ is: 6 })
The default error messages depend on the type of length validation being performed. You can personalize these messages using the wrongLength
, tooLong
, and tooShort
options and ${count} as a placeholder for the number corresponding to the length constraint being used. You can still use the msg
(or message
) option to specify an error message (don't forget to pluralize it).
confirmation
You should use this validator when you have two text fields that should receive exactly the same content. For example, you may want to confirm an email address or a password.
1<Field name="pass" type="password" label="Password" component={renderField} /> 2<Field name="confirmation" type="password" label="Confirmation" component={renderField} 3 validate={confirmation({ field: 'pass', fieldLabel: 'Password' })} /> 4 5// Within a FormSection 6<FormSection name="section"> 7 <Field name="pass" type="password" label="Password" component={renderField} /> 8 <Field name="confirmation" type="password" label="Confirmation" component={renderField} 9 validate={confirmation({ field: 'section.pass', fieldLabel: 'Password' })} /> 10</FormSection>
There is also a caseSensitive
option that you can use to define whether the confirmation constraint will be case sensitive or not. This option defaults to true (see default options).
Examples
1confirmation({ field: 'email' }) 2confirmation({ field: 'section.email' }) 3confirmation({ field: 'email', fieldLabel: 'Email' }) 4confirmation({ field: 'email', fieldLabel: 'Email', caseSensitive: false })
The default error message for this validator is "doesn't match ${fieldLabel || field}".
format
Validates the value by testing whether it match a given regular expression, which is specified using the with
option.
1<Field name="legacyCode" type="text" label="Legacy Code" component={renderField} 2 validate={format({ with: /^[a-z]+$/i, message: 'Only allows letters' })} />
Alternatively, you can require that the specified value does not match the regular expression by using the without
option.
Examples
1format({ with: /[a-z0-9]/i }) 2format({ without: /#@%&\!\:\?\+\=/i }) // doesn't allow these chars: '#@%&!:?+='
The default error message is "is invalid".
acceptance
This method validates that a checkbox on the user interface was checked. This is typically used when the user needs to agree to your application's terms of service, confirm that some text is read, or any similar concept.
1<Field name="terms" type="checkbox" label="I accept the terms of service" 2 component={renderField} validate={acceptance()} />
It can also receive an accept
option, which determines the allowed values that will be considered as accepted. It defaults to ['1', 'true'] (see default options).
Examples
1acceptance({ accept: 'yes' }) 2acceptance({ accept: ['TRUE', 'accepted'] })
The default error message for this validator is "must be accepted".
inclusion
Validates that the value is included in a given set.
1<Field name="size" type="text" label="Size" component={renderField} 2 validate={inclusion({ in: ['small', 'medium', 'large'] })} />
The inclusion validator has an option in
that receives the set of values that will be accepted. The in
option has an alias called within
that you can use for the same purpose, if you'd like to.
There is also a caseSensitive
option that you can use to define whether the match will be case sensitive or not. This option defaults to true (see default options).
Examples
1inclusion({ in: [1, 2, 3, 4] }) 2inclusion({ in: ['blue', 'white', 'red'], caseSensitive: false })
The default error message for this validator is "is not included in the list".
exclusion
Validates that the value is not included in a given set.
1<Field name="subdomain" type="text" label="Subdomain" 2 component={renderField} validate={exclusion({ in: ['www', 'us', 'ca'] })} />
The exclusion validator has an option in
that receives the set of values that will not be accepted for the validated attributes. The in
option has an alias called within
that you can use for the same purpose, if you'd like to.
There is also a caseSensitive
option that you can use to define whether the match will be case sensitive or not. This option defaults to true (see default options).
Examples
1exclusion({ in: [1, 2, 3, 4] }) 2exclusion({ in: ['apple', 'banana'], caseSensitive: false })
The default error message is "${value} is reserved".
absence
Validates that the specified value are absent. It uses the trim()
method to check if the value is not a blank string, that is, a string that is either empty or consists of whitespace.
1<Field name="name" type="text" label="Name" 2 component={renderField} validate={absence()} />
The default error message is "must be blank".
url
Validates that the specified value is a valid URL.
1<Field name="url" type="text" label="URL" 2 component={renderField} validate={url()} />
The url validator has an option protocol
(or its alias protocols
) that receives the set of protocols that will be accepted. This option default to ['http', 'https'] (see default options).
The other url constraint options are (all true by default):
protocolIdentifier
- if set to false your URL doesn't have to start with{{protocol}}://
emptyProtocol
- if set to false, doesn't accept URLs starting just with//
basicAuth
- accepts or not basic authenticationipv4
- accepts or not an IPv4 address as a hostipv6
- accepts or not an IPv6 address as a hosthost
- accepts or not a domain + TLD as a hostlocal
- accepts or not 'localhost' as a hostport
- accepts or not a portpath
- accepts or not a pathsearch
- accepts or not a query stringhash
- accepts or not a hash
Examples
1url({ protocols: ['http', 'https'] }) 2url({ protocol: 'http', ipv4: false, ipv6: false }) 3url({ protocol: 'ftp', port: false, basicAuth: false, hash: false })
The default error message is "is not a valid URL".
See also parseURL
Note: As of version 3.0.0, this method doesn't exclude any ip addresses anymore (like private & local networks). To re-implement this feature, you can use the url.parseURL helper and add a custom validator, like this:
1// Private and local networks not allowed 2const REG = new RegExp( 3 '^(?:(?:10|127)(?:\\.\\d{1,3}){3})|' + 4 '(?:(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})|' + 5 '(?:172\\.(?:1[6-9]|2\\d|3[0-1]))' 6) 7 8const ipValidator = addValidator({ 9 validator: function(options, value, allValues) { 10 let info = url.parseURL(value, options) 11 if (!info) return false 12 if (info.ipv4 && REG.test(info.ipv4)) { 13 return { 14 id: 'form.errors.private_url', 15 defaultMessage: 'Private and local networks are not allowed', 16 } 17 } 18 } 19})
file
Validates that the specified value is a valid File or FileList.
1<Field name="file" type="file" label="File" 2 component={renderFileField} validate={file()} />
The possible file constraint options are:
accept
- The value is a file (or a list of files) that match a comma-separated list of allowed file extensions or MIME typesminSize
- The value is a file (or a list of files) that cannot be smaller than the specified sizemaxSize
- The value is a file (or a list of files) that cannot be bigger than the specified sizeminFiles
- The value is a list of files that cannot be smaller than the specified lengthmaxFiles
- The value is a list of files that cannot be bigger than the specified length
Examples
1file() 2file({ accept: 'image/png, image/jpeg' }) 3file({ accept: '.png, .jpg, .jpeg' }) 4file({ accept: 'image/*' }) // Accept any file with an image/* MIME type 5file({ minSize: '5 MB', maxSize: '1 TB' }) 6file({ minFiles: 2, maxFiles: 5 })
The default error messages are:
- "is not a file"
- "invalid file type" / "invalid file types ({count})"
- "is too small (minimum is {size})" / "{count} files are too small (minimum is {size} each)"
- "is too big (maximum is {size})" / "{count} files are too big (maximum is {size} each)"
- "invalid number of files (minimum is {count})"
- "invalid number of files (maximum is {count})"
Note: size units supported: B, KB, MB, GB, TB, PB, EB
Note: file inputs are only compatible with
file
,required
orabsence
validators
Note: incorrect
minSize
ormaxSize
options will display an error in the console
Note: for an optional file input, don't forget to pass
allowBlank: true
validateForm
Helper that turns a validation object into a validate function.
Examples
1import { required, length, validateForm } from 'redux-form-validators' 2 3const validate = validateForm({ 4 firstName: required(), 5 lastName: required(), 6 // FormSection 7 secureSection: { 8 password: [required(), length({ min: 8 }), 9 confirmation: confirmation({ field: 'secureSection.password' }) 10 } 11}) 12 13... 14 15export default reduxForm({ 16 form: 'validationFormExample', 17 validate, 18})(ValidationFormExample)
Note: For performance reasons,
validateForm
is not memoized. Use it always outside of the render function to avoid problems.
combine
Combine several validators. This helper exists for 2 reasons:
- when validators are combined using an array, it sometimes forces the component to be re-rendered (thank you @futpib for pointing it out). This is due to the way React handle properties comparison. This demo shows the issue (see how the email field is forced to be re-rendered).
- react-final-form doesn't support arrays of validators.
Examples
1<Field name="email" type="email" label="Email" 2 component={renderField} validate={combine(required(), email())} /> 3 4<Field name="password" type="password" label="Password" 5 component={renderField} validate={combine(required(), length({ min: 8 }))} />
Note: You don't need to use
combine
withvalidateForm
Default options
redux-form-validators comes with default options:
1{ 2 memoize: true, 3 allowBlank: false, 4 urlProtocols: ['http', 'https'], 5 dateFormat: 'yyyy-mm-dd', 6 dateYmd: 'ymd', 7 accept: ['1', 'true'], 8 caseSensitive: true, // confirmation, inclusion, exclusion 9 pluralRules: { // See the "i18n and react-intl" section 10 0: 'zero', 11 1: 'one' 12 } 13};
But you can easily change them:
1import Validators from 'redux-validators' 2 3// Override dateFormat & urlProtocols 4Object.assign(Validators.defaultOptions, { 5 dateFormat: 'mm/dd/yyyy', 6 urlProtocols: ['http', 'https', 'ftp'], 7})
Memoization
Since version 7.0 of Redux-form, memoization is needed for inline validation. In some cases, you might want to disable it though. To do so:
- set
Validators.defaultOptions.memoize
to false - OR set
memoize
validator's option to false (e.g. presence({ memoize: false }))
And if you want to keep the memoization but want to override it:
1// Global memoization 2// This function usually returns a unique key depending on the options passed 3// $super represents the default memoize function 4Validators.defaultOptions.memoize = (options, $super) => { 5 return ... // string key 6} 7 8// Specific validation (inline-validation) 9length({ 10 min: 2, 11 if: () => this.state.foo, 12 memoize: (opts, $super) => $super(opts) + this.state.foo 13}) 14 15// General validation 16const validLen = length({ min: 2, if: () => ..., memoize: false }) 17 18<Field name="test" type="text" label="Test" 19 component={renderField} validate={validLen} />
i18n and react-intl
By default, all errors messages are in english and are pluralized if needed (basic support) but you can use react-intl to support different languages. All you need to do is to insert the following lines:
1import Validators from 'redux-form-validators' 2import { FormattedMessage } from 'react-intl' 3 4Validators.formatMessage = function(msg) { 5 return <FormattedMessage {...msg.props || msg} /> 6}
Note: You can also implement your own i18n/pluralization module by overriding
Validators.formatMessage
. The first argument is a javascript object compatible with react-intl:
1{ 2 id: "form.errors.greaterThan", 3 defaultMessage: "must be greater than {count, number}", 4 values: { count: 10 } 5}
Note: You can also change the default plural rules or file size formats:
1// Plural rules 2Validators.pluralRules = { 3 1: 'one', 5: 'one', 7: 'one', 8: 'one', 9: 'one', 10: 'one', 4 2: 'two', 3: 'two', 5 4: 'few', 6 6: 'many' 7} 8let msg = '{count, plural, one {foo} two {bar} few {fooo} many {baaar} other {foobar}}' 9 10// Size format 11const FR_UNITS = { 12 B: 'octets', 13 KB: 'Ko', 14 ... 15} 16Validators.formatSize = function (size, unit) { 17 return size + ' ' + FR_UNITS[unit] 18} 19file({ minSize: '5MB' }) // -> is too small (minimum is 5 Mo) 20file({ minSize: 500 }) // -> is too small (minimum is 500 octets)
And if you're using babel-plugin-react-intl to extract your application messages, you'll need to add a new plugin entry in your webpack config (example):
1["react-intl", { 2 "messagesDir": ..., 3 "languages": ..., 4 // /!\ it's important to keep a relative path here 5 "moduleSourceName": "./redux-form-validators", 6}, 'redux-form-validators']
Default messages override
To override the default messages globally:
1Object.assign(Validators.messages, { 2 email: { 3 id: "form.errors.email", 4 defaultMessage: "is not a valid email address" 5 }, 6 presence: { 7 id: "form.errors.presence", 8 defaultMessage: "is missing" 9 }, 10 tooShort: { 11 id: "form.errors.tooShort", 12 defaultMessage: "is too short: {count, number} chars minimum" 13 }, 14 ... 15})
OR even simpler if you don't override formatMessage (and don't need ids):
1Object.assign(Validators.messages, { 2 email: "is not a valid email address", 3 presence: "is missing", 4 tooShort: "is too short: {count, number} chars minimum", 5 ... 6})
Note: This won't work with react-intl, as you load the messages from a json file
Common validation options
allowBlank
This option will let validation pass if the value is blank, like an empty string for example.
1<Field name="name" type="text" label="Name" component={renderField} 2 validate={length({ '=': 5, allowBlank: true })} />
Not available for: required, absence, acceptance & confirmation.
Note: If you're already using the required validator you don't need to care about the allowBlank option.
message (alias: msg)
As you've already seen, the message
option lets you specify the message that will be added to the errors collection when validation fails. When this option is not used, redux-form-validators
will use the respective default error message for each validator. The message
option accepts a String, a Hash or a FormattedMessage.
1format({ with: /^[a-z]+$/i, message: 'Letters only' }) 2format({ with: /^[a-z]+$/i, message: { 3 defaultMessage: 'Letters only' } }) 4 5// I18n with react-intl 6format({ with: /^[a-z]+$/i, message: { id: 'form.errors.alpha', 7 defaultMessage: 'Letters only' } }) 8format({ with: /^[a-z]+$/i, message: <FormattedMessage id="form.errors.alpha" 9 defaultMessage="Letters only" /> }) 10 11// Redefine only certain messages and use interpolation 12length({ msg: { tooShort: 'too short', tooLong: 'too long' }, in: [2, 8] }) 13length({ msg: { tooShort: { id: 'errors.length.min', 14 defaultMessage: 'too short' } }, min: 2 }) 15length({ msg: { tooShort: <FormattedMessage id="errors.length.min" 16 defaultMessage="too short" /> }, min: 2 }) 17length({ msg: { tooShort: 'min {count, number} characters' }, min: 2, max: 8 }) 18 //=> tooLong message remains the default message 19 20// Version >= 3.3.0 (aliases) 21length({ msg: { min: 'too short', max: 'too long' }, in: [2, 8] }) 22numericality({ msg: { '>=': 'must be at least {count, number} years old' }, '>=': 18 }) 23date({ msg: { '>': 'must be in the future' }, '>': 'today' })
Message key aliases
Date
- 'dateFormat', 'format'
- 'dateInvalid', 'invalid'
- 'dateRange', 'range', '=', '!=', '>', '>=', '<', '<=' (operators only match with their specific validation)
- 'email', 'invalid'
- 'emailDomain', 'domain'
File
- 'fileTooFew', 'tooFew', 'minFiles'
- 'fileTooMany', 'tooMany', 'maxFiles'
- 'fileAccept', 'accept'
- 'fileTooSmall', 'tooSmall', 'minSize'
- 'fileTooBig', 'tooBig', 'maxSize'
Length
- 'wrongLength', 'is', '='
- 'tooLong', 'maximum', 'max'
- 'tooShort', 'minimum', 'min'
Numericality
- 'notANumber', 'NaN'
- 'notAnInteger', 'int'
- 'equalTo', '='
- 'otherThan', '!='
- 'greaterThan', '>'
- 'greaterThanOrEqualTo', '>='
- 'lessThan', '<'
- 'lessThanOrEqualTo', '<='
Note: all messages are internally converted into javascript objects (see i18n and react-intl), so if you pass a FormattedMessage as an argument, don't expect it to be returned as it.
Conditional validation
Using a function with if
and unless
Finally, it's possible to associate if
and unless
with a function which will be called. Using a function gives you the ability to write an inline condition instead of a separate method. This option is best suited for one-liners.
1<Field name="surname" type="text" label="Surname" component={renderField} 2 validate={presence({ if: (values, value, props, name) => '' !== values.name })} />
Note: In some cases, the memoization can mess with
if
andunless
methods which can refer to out-of-the-scope variables. See memoization for further information.
Adding a validator
1const alphaValidator = addValidator({ 2 defaultMessage: "Letters only", 3 validator: function(options, value, allValues) { 4 return (options.lowerCase ? /^[a-z]+$/ : /^[a-z]+$/i).test(value) 5 } 6}) 7 8<Field name="name" type="text" label="Name" component={renderField} 9 validate={alphaValidator({ lowerCase: true, allowBlank: true })} /> 10 11// Version >= 2.0.0 only 12const digitValidator = addValidator({ 13 validator: function(options, value, allValues) { 14 if (options.digits !== value.replace(/[^0-9]/g, '').length) { 15 return { 16 id: "form.errors.custom", 17 defaultMessage: "must contain {count, number} {count, plural, one {digit} other {digits}})", 18 values: { count: options.digits }, 19 } 20 } 21 } 22}) 23 24<Field name="digits" type="text" label="4 digits" 25 component={renderField} validate={digitValidator({ digits: 4 })} />
defaultMessage
accepts a String, a Hash or a FormattedMessage. See the message
option. Its default value is is not valid
.
Note: As of version 2.0.0, you can now return a message directly if invalid (allowing things like pluralization). For backward compatibility, if you return a boolean, the validator will return the defaultMessage if invalid.
Note: you'll still be able to use the common options (
message
,allowBlank
&memoize
) and the conditional validation (if
andunless
).
Date helpers
parseDate
parser used to validate dates.
Signature: parseDate(dateString, format[, ymd])
Examples:
1import { date } from 'redux-form-validators' 2let parseDate = date.parseDate 3 4parseDate('12/31/2017', 'mm/dd/yyyy') => new Date(2017, 11, 31) 5parseDate('2016/01', 'yyyy/mm')) => new Date(2016, 1, 1) 6parseDate('12/01', 'mm/dd')) => new Date(1970, 11, 1) 7 8// Custom ymd 9parseDate('12/31/2017', 'mm/jj/aaaa', 'amj') => new Date(2017, 11, 31) 10 11// Error 12parseDate('12122016', 'mm/dd/yyyy') => Invalid date
formatDate
formatter used to display dates.
Signature: formatDate(date, format[, ymd])
Examples:
1import { date } from 'redux-form-validators' 2let formatDate = date.formatDate 3 4formatDate(new Date(2017, 11, 31), 'mm/dd/yyyy') => '12/31/2017' 5formatDate(new Date(2016, 1, 1), 'yyyy/mm')) => '2016/01' 6formatDate(new Date(1970, 11, 1), 'mm/dd')) => '12/01' 7 8// Custom ymd 9formatDate(new Date(2017, 11, 31), 'mm/jj/aaaa', 'amj') => '12/31/2017' 10 11// Error 12formatDate(new Date(NaN), 'mm/dd/yyyy') => null 13formatDate(null, 'mm/dd/yyyy') => null 14formatDate({}, 'mm/dd/yyyy') => null
URL helper
parseURL
parser used to validate URLs
Signature: parseURL(url[, options])
- options are the same as described for url
- returns null if invalid
- otherwise returns an object filled with the elements found
Examples:
1import { url } from 'redux-form-validators' 2let parseURL = url.parseURL 3 4parseURL('http://example.com/stuff') 5// { protocol: 'http', host: 'example.com', path: '/stuff' } 6 7parseURL('http://localhost:8080') 8// { protocol: 'http', host: 'localhost', port: 8080 } 9 10parseURL('//212.78.3.17:4000') 11// { ipv4: '212.78.3.17', port: 4000 } 12 13parseURL('http://[::1]:3000') 14// { ipv6: '::1', port: 3000, protocol: 'http' } 15 16parseURL('http://userid:pass@example.com') 17// { basicAuth: { username: 'userid', password: 'pass' }, ... }
Send some love:
You like this package?
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
Found 5/30 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 5 are checked with a SAST tool
Reason
124 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-6chw-6frg-f759
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-whgm-jr23-g3j9
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-8w4h-3cm3-2pm2
- Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7
- Warn: Project is vulnerable to: GHSA-vc8w-jr9v-vj7f
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-x9w5-v3q2-3rhw
- Warn: Project is vulnerable to: GHSA-w8qv-6jwh-64r5
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-3wcq-x3mq-6r9p
- Warn: Project is vulnerable to: GHSA-vh7m-p724-62c2
- Warn: Project is vulnerable to: GHSA-r9p9-mrjm-926w
- Warn: Project is vulnerable to: GHSA-434g-2637-qmqr
- Warn: Project is vulnerable to: GHSA-49q7-c7j4-3p7m
- Warn: Project is vulnerable to: GHSA-977x-g7h5-7qgw
- Warn: Project is vulnerable to: GHSA-f7q4-pwc6-w24p
- Warn: Project is vulnerable to: GHSA-fc9h-whq2-v747
- Warn: Project is vulnerable to: GHSA-4gmj-3p3h-gm8h
- Warn: Project is vulnerable to: GHSA-3gx7-xhv7-5mx3
- Warn: Project is vulnerable to: GHSA-6h5x-7c5m-7cr7
- Warn: Project is vulnerable to: GHSA-rv95-896h-c2vc
- Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx
- Warn: Project is vulnerable to: GHSA-2j2x-2gpw-g8fm
- Warn: Project is vulnerable to: GHSA-74fj-2j2h-c42q
- Warn: Project is vulnerable to: GHSA-pw2r-vq6v-hr8c
- Warn: Project is vulnerable to: GHSA-jchw-25xp-jwwc
- Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp
- Warn: Project is vulnerable to: GHSA-8r6j-v8pm-fqw3
- Warn: Project is vulnerable to: MAL-2023-462
- Warn: Project is vulnerable to: GHSA-xf7w-r453-m56c
- Warn: Project is vulnerable to: GHSA-w457-6q6x-cgp9
- Warn: Project is vulnerable to: GHSA-62gr-4qp9-h98f
- Warn: Project is vulnerable to: GHSA-f52g-6jhx-586p
- Warn: Project is vulnerable to: GHSA-2cf5-4w76-r9qv
- Warn: Project is vulnerable to: GHSA-3cqr-58rm-57f8
- Warn: Project is vulnerable to: GHSA-g9r4-xpmj-mj65
- Warn: Project is vulnerable to: GHSA-q2c6-c6pm-g3gh
- Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44
- Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-pfq8-rq6v-vf5m
- Warn: Project is vulnerable to: GHSA-6x33-pw7p-hmpq
- Warn: Project is vulnerable to: GHSA-c7qv-q95q-8v27
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-78xj-cgh5-2h22
- Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp
- Warn: Project is vulnerable to: GHSA-8j8c-7jfh-h6hx
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp
- Warn: Project is vulnerable to: GHSA-76p3-8jx3-jpfq
- Warn: Project is vulnerable to: GHSA-3rfm-jhwj-7488
- Warn: Project is vulnerable to: GHSA-hhq3-ff78-jv3g
- Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-779f-wgxg-qr8f
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m / GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-fhjf-83wg-r2j9
- Warn: Project is vulnerable to: GHSA-r683-j2x4-v87g
- Warn: Project is vulnerable to: GHSA-92xj-mqp7-vmcj
- Warn: Project is vulnerable to: GHSA-wxgw-qj99-44c2
- Warn: Project is vulnerable to: GHSA-5rrq-pxf6-6jx5
- Warn: Project is vulnerable to: GHSA-8fr3-hfg3-gpgp
- Warn: Project is vulnerable to: GHSA-gf8q-jrpm-jvxq
- Warn: Project is vulnerable to: GHSA-2r2c-g63r-vccr
- Warn: Project is vulnerable to: GHSA-cfm4-qjh2-4765
- Warn: Project is vulnerable to: GHSA-x4jg-mjrx-434g
- Warn: Project is vulnerable to: GHSA-9v62-24cr-58cx
- Warn: Project is vulnerable to: GHSA-r8f7-9pfq-mjmv
- Warn: Project is vulnerable to: GHSA-cwx2-736x-mf6w
- Warn: Project is vulnerable to: GHSA-v39p-96qg-c8rf
- Warn: Project is vulnerable to: GHSA-8v63-cqqc-6r2c
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
- Warn: Project is vulnerable to: GHSA-566m-qj78-rww5
- Warn: Project is vulnerable to: GHSA-hwj9-h5mp-3pm3
- Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-7mwh-4pqv-wmr8
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg
- Warn: Project is vulnerable to: GHSA-h9rv-jmmf-4pgx
- Warn: Project is vulnerable to: GHSA-hxcc-f52p-wc94
- Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p
- Warn: Project is vulnerable to: GHSA-jv35-xqg7-f92r
- Warn: Project is vulnerable to: GHSA-4g88-fppr-53pp
- Warn: Project is vulnerable to: GHSA-4jqc-8m5r-9rpr
- Warn: Project is vulnerable to: GHSA-c9g6-9335-x697
- Warn: Project is vulnerable to: GHSA-vx3p-948g-6vhq
- Warn: Project is vulnerable to: GHSA-j44m-qm6p-hp7m
- Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9
- Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-r628-mhmh-qjhw
- Warn: Project is vulnerable to: GHSA-9r2w-394v-53qc
- Warn: Project is vulnerable to: GHSA-qq89-hq3f-393p
- Warn: Project is vulnerable to: GHSA-4wf5-vphf-c2xc
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-7p7h-4mm5-852v
- Warn: Project is vulnerable to: GHSA-662x-fhqg-9p8v
- Warn: Project is vulnerable to: GHSA-394c-5j6w-4xmx
- Warn: Project is vulnerable to: GHSA-78cj-fxph-m83p
- Warn: Project is vulnerable to: GHSA-fhg7-m89q-25r3
- Warn: Project is vulnerable to: GHSA-9m6j-fcg5-2442
- Warn: Project is vulnerable to: GHSA-hh27-ffr2-f2jc
- Warn: Project is vulnerable to: GHSA-rqff-837h-mm52
- Warn: Project is vulnerable to: GHSA-8v38-pw62-9cw2
- Warn: Project is vulnerable to: GHSA-hgjh-723h-mx2j
- Warn: Project is vulnerable to: GHSA-jf5r-8hm2-f872
- Warn: Project is vulnerable to: GHSA-wr3j-pwj9-hqq6
- Warn: Project is vulnerable to: GHSA-g78m-2chm-r7qv
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
1.4
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to redux-form-validators
redux-form
A higher order component decorator for forms using Redux and React
@types/redux-form
TypeScript definitions for redux-form
@rxweb/reactive-form-validators
[![Build Status](https://dev.azure.com/ajayojha/rxweb/_apis/build/status/rxweb-CI?branchName=master)](https://dev.azure.com/ajayojha/rxweb/_build/latest?definitionId=39&branchName=master) [![Gitter](https://badges.gitter.im/rx-web/Lobby.svg)](https://git
@vuelidate/core
Simple, lightweight model-based validation for Vue.js