redux-freeform 6.1.0 → 6.2.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -115,6 +115,8 @@ validatorFns[ONLY_EXPIRATION_DATE] = (value, args, form) =>
|
|
|
115
115
|
This validator will check if the value has more than 6 numeric characters
|
|
116
116
|
We have to allow for some numeric characters to account for business
|
|
117
117
|
names that include numbers like "3M Company" or "Smith Street Trust 40389"
|
|
118
|
+
|
|
119
|
+
1/25 - This has been superseded by the includesPotentialCardNumber validator
|
|
118
120
|
*/
|
|
119
121
|
const NO_MORE_THAN_SIX_NUMBERS = 'validator/NO_MORE_THAN_SIX_NUMBERS';
|
|
120
122
|
const NO_MORE_THAN_SIX_NUMBERS_ERROR = 'error/NO_MORE_THAN_SIX_NUMBERS';
|
|
@@ -129,6 +131,81 @@ validatorFns[NO_MORE_THAN_SIX_NUMBERS] = (value) => {
|
|
|
129
131
|
return !/(\d.*){7,}/.test(value);
|
|
130
132
|
};
|
|
131
133
|
|
|
134
|
+
/*
|
|
135
|
+
* 1/25 - Prevent users from entering full credit card numbers in the "name" field.
|
|
136
|
+
*
|
|
137
|
+
* This validator is designed to reduce the accidental inclusion of credit card numbers
|
|
138
|
+
* in fields where they don't belong (e.g., the name field). It identifies a potential
|
|
139
|
+
* credit card number based on the following criteria:
|
|
140
|
+
*
|
|
141
|
+
* - It consists of 8 to 20 digits.
|
|
142
|
+
* - Digits may be separated by optional spaces or hyphens.
|
|
143
|
+
* - It must pass the Luhn algorithm check.
|
|
144
|
+
*
|
|
145
|
+
* Note:
|
|
146
|
+
* A string passing the Luhn algorithm is necessary but not sufficient to conclusively
|
|
147
|
+
* determine that the string is a valid credit card number.
|
|
148
|
+
*
|
|
149
|
+
* For more details on the Luhn algorithm, refer to:
|
|
150
|
+
* https://stripe.com/en-ca/resources/more/how-to-use-the-luhn-algorithm-a-guide-in-applications-for-businesses#luhn-algorithm-formula
|
|
151
|
+
*/
|
|
152
|
+
|
|
153
|
+
function luhnValid(string) {
|
|
154
|
+
if (!string) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const digits = string.match(/\d/g);
|
|
159
|
+
if (!digits) {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const digitArray = digits.map(Number);
|
|
164
|
+
let totalSum = 0;
|
|
165
|
+
|
|
166
|
+
// Start from the right.
|
|
167
|
+
for (let i = digitArray.length - 1; i >= 0; i -= 2) {
|
|
168
|
+
const lastDigit = digitArray[i];
|
|
169
|
+
const secondToLastDigit = digitArray[i - 1];
|
|
170
|
+
|
|
171
|
+
if (secondToLastDigit !== undefined) {
|
|
172
|
+
// Double the value of the second-to-last digit and continue doing the same for every second digit.
|
|
173
|
+
let secondToLastDigitDoubled = secondToLastDigit * 2;
|
|
174
|
+
|
|
175
|
+
// If the result of any doubling operation is greater than nine,
|
|
176
|
+
// then add the digits of the result together to obtain a single-digit number.
|
|
177
|
+
if (secondToLastDigitDoubled > 9) {
|
|
178
|
+
secondToLastDigitDoubled -= 9;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
totalSum += secondToLastDigitDoubled;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Find the sum of all the digits that you didn't double and the new values that you got from doubling.
|
|
185
|
+
totalSum += lastDigit;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Determine if the total sum is a multiple of ten.
|
|
189
|
+
// According to the Luhn algorithm, the number is considered to be valid if the total ends in zero.
|
|
190
|
+
return totalSum % 10 === 0;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const INCLUDES_POTENTIAL_CARD_NUMBER =
|
|
194
|
+
'validator/INCLUDES_POTENTIAL_CARD_NUMBER';
|
|
195
|
+
const INCLUDES_POTENTIAL_CARD_NUMBER_ERROR =
|
|
196
|
+
'error/INCLUDES_POTENTIAL_CARD_NUMBER';
|
|
197
|
+
createValidator(
|
|
198
|
+
INCLUDES_POTENTIAL_CARD_NUMBER,
|
|
199
|
+
INCLUDES_POTENTIAL_CARD_NUMBER_ERROR
|
|
200
|
+
);
|
|
201
|
+
validatorFns[INCLUDES_POTENTIAL_CARD_NUMBER] = (value) => {
|
|
202
|
+
// This is the same regex currently used in Ghenghis
|
|
203
|
+
// A potential credit card number is a sequence of 8 to 20 digits, with optional spaces or hyphens between them
|
|
204
|
+
const regexString = '(?:\\d[ -]*){8,20}';
|
|
205
|
+
const regex = new RegExp(regexString);
|
|
206
|
+
return regex.test(value) && luhnValid(value);
|
|
207
|
+
};
|
|
208
|
+
|
|
132
209
|
const NUMBER_LESS_THAN = 'validator/NUMBER_LESS_THAN';
|
|
133
210
|
const NUMBER_LESS_THAN_ERROR = 'error/NUMBER_LESS_THAN';
|
|
134
211
|
const numberLessThan = createValidator(
|
|
@@ -111,6 +111,8 @@ validatorFns[ONLY_EXPIRATION_DATE] = (value, args, form) =>
|
|
|
111
111
|
This validator will check if the value has more than 6 numeric characters
|
|
112
112
|
We have to allow for some numeric characters to account for business
|
|
113
113
|
names that include numbers like "3M Company" or "Smith Street Trust 40389"
|
|
114
|
+
|
|
115
|
+
1/25 - This has been superseded by the includesPotentialCardNumber validator
|
|
114
116
|
*/
|
|
115
117
|
const NO_MORE_THAN_SIX_NUMBERS = 'validator/NO_MORE_THAN_SIX_NUMBERS';
|
|
116
118
|
const NO_MORE_THAN_SIX_NUMBERS_ERROR = 'error/NO_MORE_THAN_SIX_NUMBERS';
|
|
@@ -125,6 +127,81 @@ validatorFns[NO_MORE_THAN_SIX_NUMBERS] = (value) => {
|
|
|
125
127
|
return !/(\d.*){7,}/.test(value);
|
|
126
128
|
};
|
|
127
129
|
|
|
130
|
+
/*
|
|
131
|
+
* 1/25 - Prevent users from entering full credit card numbers in the "name" field.
|
|
132
|
+
*
|
|
133
|
+
* This validator is designed to reduce the accidental inclusion of credit card numbers
|
|
134
|
+
* in fields where they don't belong (e.g., the name field). It identifies a potential
|
|
135
|
+
* credit card number based on the following criteria:
|
|
136
|
+
*
|
|
137
|
+
* - It consists of 8 to 20 digits.
|
|
138
|
+
* - Digits may be separated by optional spaces or hyphens.
|
|
139
|
+
* - It must pass the Luhn algorithm check.
|
|
140
|
+
*
|
|
141
|
+
* Note:
|
|
142
|
+
* A string passing the Luhn algorithm is necessary but not sufficient to conclusively
|
|
143
|
+
* determine that the string is a valid credit card number.
|
|
144
|
+
*
|
|
145
|
+
* For more details on the Luhn algorithm, refer to:
|
|
146
|
+
* https://stripe.com/en-ca/resources/more/how-to-use-the-luhn-algorithm-a-guide-in-applications-for-businesses#luhn-algorithm-formula
|
|
147
|
+
*/
|
|
148
|
+
|
|
149
|
+
function luhnValid(string) {
|
|
150
|
+
if (!string) {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const digits = string.match(/\d/g);
|
|
155
|
+
if (!digits) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const digitArray = digits.map(Number);
|
|
160
|
+
let totalSum = 0;
|
|
161
|
+
|
|
162
|
+
// Start from the right.
|
|
163
|
+
for (let i = digitArray.length - 1; i >= 0; i -= 2) {
|
|
164
|
+
const lastDigit = digitArray[i];
|
|
165
|
+
const secondToLastDigit = digitArray[i - 1];
|
|
166
|
+
|
|
167
|
+
if (secondToLastDigit !== undefined) {
|
|
168
|
+
// Double the value of the second-to-last digit and continue doing the same for every second digit.
|
|
169
|
+
let secondToLastDigitDoubled = secondToLastDigit * 2;
|
|
170
|
+
|
|
171
|
+
// If the result of any doubling operation is greater than nine,
|
|
172
|
+
// then add the digits of the result together to obtain a single-digit number.
|
|
173
|
+
if (secondToLastDigitDoubled > 9) {
|
|
174
|
+
secondToLastDigitDoubled -= 9;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
totalSum += secondToLastDigitDoubled;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Find the sum of all the digits that you didn't double and the new values that you got from doubling.
|
|
181
|
+
totalSum += lastDigit;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Determine if the total sum is a multiple of ten.
|
|
185
|
+
// According to the Luhn algorithm, the number is considered to be valid if the total ends in zero.
|
|
186
|
+
return totalSum % 10 === 0;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const INCLUDES_POTENTIAL_CARD_NUMBER =
|
|
190
|
+
'validator/INCLUDES_POTENTIAL_CARD_NUMBER';
|
|
191
|
+
const INCLUDES_POTENTIAL_CARD_NUMBER_ERROR =
|
|
192
|
+
'error/INCLUDES_POTENTIAL_CARD_NUMBER';
|
|
193
|
+
createValidator(
|
|
194
|
+
INCLUDES_POTENTIAL_CARD_NUMBER,
|
|
195
|
+
INCLUDES_POTENTIAL_CARD_NUMBER_ERROR
|
|
196
|
+
);
|
|
197
|
+
validatorFns[INCLUDES_POTENTIAL_CARD_NUMBER] = (value) => {
|
|
198
|
+
// This is the same regex currently used in Ghenghis
|
|
199
|
+
// A potential credit card number is a sequence of 8 to 20 digits, with optional spaces or hyphens between them
|
|
200
|
+
const regexString = '(?:\\d[ -]*){8,20}';
|
|
201
|
+
const regex = new RegExp(regexString);
|
|
202
|
+
return regex.test(value) && luhnValid(value);
|
|
203
|
+
};
|
|
204
|
+
|
|
128
205
|
const NUMBER_LESS_THAN = 'validator/NUMBER_LESS_THAN';
|
|
129
206
|
const NUMBER_LESS_THAN_ERROR = 'error/NUMBER_LESS_THAN';
|
|
130
207
|
const numberLessThan = createValidator(
|
|
@@ -117,6 +117,8 @@
|
|
|
117
117
|
This validator will check if the value has more than 6 numeric characters
|
|
118
118
|
We have to allow for some numeric characters to account for business
|
|
119
119
|
names that include numbers like "3M Company" or "Smith Street Trust 40389"
|
|
120
|
+
|
|
121
|
+
1/25 - This has been superseded by the includesPotentialCardNumber validator
|
|
120
122
|
*/
|
|
121
123
|
const NO_MORE_THAN_SIX_NUMBERS = 'validator/NO_MORE_THAN_SIX_NUMBERS';
|
|
122
124
|
const NO_MORE_THAN_SIX_NUMBERS_ERROR = 'error/NO_MORE_THAN_SIX_NUMBERS';
|
|
@@ -131,6 +133,81 @@
|
|
|
131
133
|
return !/(\d.*){7,}/.test(value);
|
|
132
134
|
};
|
|
133
135
|
|
|
136
|
+
/*
|
|
137
|
+
* 1/25 - Prevent users from entering full credit card numbers in the "name" field.
|
|
138
|
+
*
|
|
139
|
+
* This validator is designed to reduce the accidental inclusion of credit card numbers
|
|
140
|
+
* in fields where they don't belong (e.g., the name field). It identifies a potential
|
|
141
|
+
* credit card number based on the following criteria:
|
|
142
|
+
*
|
|
143
|
+
* - It consists of 8 to 20 digits.
|
|
144
|
+
* - Digits may be separated by optional spaces or hyphens.
|
|
145
|
+
* - It must pass the Luhn algorithm check.
|
|
146
|
+
*
|
|
147
|
+
* Note:
|
|
148
|
+
* A string passing the Luhn algorithm is necessary but not sufficient to conclusively
|
|
149
|
+
* determine that the string is a valid credit card number.
|
|
150
|
+
*
|
|
151
|
+
* For more details on the Luhn algorithm, refer to:
|
|
152
|
+
* https://stripe.com/en-ca/resources/more/how-to-use-the-luhn-algorithm-a-guide-in-applications-for-businesses#luhn-algorithm-formula
|
|
153
|
+
*/
|
|
154
|
+
|
|
155
|
+
function luhnValid(string) {
|
|
156
|
+
if (!string) {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const digits = string.match(/\d/g);
|
|
161
|
+
if (!digits) {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const digitArray = digits.map(Number);
|
|
166
|
+
let totalSum = 0;
|
|
167
|
+
|
|
168
|
+
// Start from the right.
|
|
169
|
+
for (let i = digitArray.length - 1; i >= 0; i -= 2) {
|
|
170
|
+
const lastDigit = digitArray[i];
|
|
171
|
+
const secondToLastDigit = digitArray[i - 1];
|
|
172
|
+
|
|
173
|
+
if (secondToLastDigit !== undefined) {
|
|
174
|
+
// Double the value of the second-to-last digit and continue doing the same for every second digit.
|
|
175
|
+
let secondToLastDigitDoubled = secondToLastDigit * 2;
|
|
176
|
+
|
|
177
|
+
// If the result of any doubling operation is greater than nine,
|
|
178
|
+
// then add the digits of the result together to obtain a single-digit number.
|
|
179
|
+
if (secondToLastDigitDoubled > 9) {
|
|
180
|
+
secondToLastDigitDoubled -= 9;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
totalSum += secondToLastDigitDoubled;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Find the sum of all the digits that you didn't double and the new values that you got from doubling.
|
|
187
|
+
totalSum += lastDigit;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Determine if the total sum is a multiple of ten.
|
|
191
|
+
// According to the Luhn algorithm, the number is considered to be valid if the total ends in zero.
|
|
192
|
+
return totalSum % 10 === 0;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const INCLUDES_POTENTIAL_CARD_NUMBER =
|
|
196
|
+
'validator/INCLUDES_POTENTIAL_CARD_NUMBER';
|
|
197
|
+
const INCLUDES_POTENTIAL_CARD_NUMBER_ERROR =
|
|
198
|
+
'error/INCLUDES_POTENTIAL_CARD_NUMBER';
|
|
199
|
+
createValidator(
|
|
200
|
+
INCLUDES_POTENTIAL_CARD_NUMBER,
|
|
201
|
+
INCLUDES_POTENTIAL_CARD_NUMBER_ERROR
|
|
202
|
+
);
|
|
203
|
+
validatorFns[INCLUDES_POTENTIAL_CARD_NUMBER] = (value) => {
|
|
204
|
+
// This is the same regex currently used in Ghenghis
|
|
205
|
+
// A potential credit card number is a sequence of 8 to 20 digits, with optional spaces or hyphens between them
|
|
206
|
+
const regexString = '(?:\\d[ -]*){8,20}';
|
|
207
|
+
const regex = new RegExp(regexString);
|
|
208
|
+
return regex.test(value) && luhnValid(value);
|
|
209
|
+
};
|
|
210
|
+
|
|
134
211
|
const NUMBER_LESS_THAN = 'validator/NUMBER_LESS_THAN';
|
|
135
212
|
const NUMBER_LESS_THAN_ERROR = 'error/NUMBER_LESS_THAN';
|
|
136
213
|
const numberLessThan = createValidator(
|
package/package.json
CHANGED