parent
4488477f3b
commit
4b80587f57
5 changed files with 120 additions and 8 deletions
@ -0,0 +1,32 @@ |
||||
import { REP_DOMAIN } from '../consts/REG_EXP_PATTERNS'; |
||||
|
||||
import testNotBlank from './testNotBlank'; |
||||
import { InlineMonoText } from '../../components/Text'; |
||||
|
||||
const buildDomainTestBatch: BuildInputTestBatchFunction = ( |
||||
inputName, |
||||
onSuccess, |
||||
{ compare: dCompare, getValue } = {}, |
||||
onDomainTestFailure, |
||||
) => ({ |
||||
defaults: { compare: dCompare, getValue, onSuccess }, |
||||
tests: [ |
||||
{ |
||||
onFailure: (...args) => { |
||||
onDomainTestFailure( |
||||
<> |
||||
{inputName} can only contain lowercase alphanumeric, hyphen ( |
||||
<InlineMonoText text="-" /> |
||||
), and dot (<InlineMonoText text="." />) characters. |
||||
</>, |
||||
...args, |
||||
); |
||||
}, |
||||
test: ({ compare, value }) => |
||||
(compare[0] as boolean) || REP_DOMAIN.test(value as string), |
||||
}, |
||||
{ test: testNotBlank }, |
||||
], |
||||
}); |
||||
|
||||
export default buildDomainTestBatch; |
@ -0,0 +1,26 @@ |
||||
import { REP_IPV4 } from '../consts/REG_EXP_PATTERNS'; |
||||
|
||||
import testNotBlank from './testNotBlank'; |
||||
|
||||
const buildIPAddressTestBatch: BuildInputTestBatchFunction = ( |
||||
inputName, |
||||
onSuccess, |
||||
{ getValue } = {}, |
||||
onIPv4TestFailure, |
||||
) => ({ |
||||
defaults: { getValue, onSuccess }, |
||||
tests: [ |
||||
{ |
||||
onFailure: (...args) => { |
||||
onIPv4TestFailure( |
||||
`${inputName} should be a valid IPv4 address.`, |
||||
...args, |
||||
); |
||||
}, |
||||
test: ({ value }) => REP_IPV4.test(value as string), |
||||
}, |
||||
{ test: testNotBlank }, |
||||
], |
||||
}); |
||||
|
||||
export default buildIPAddressTestBatch; |
@ -0,0 +1,34 @@ |
||||
import testNotBlank from './testNotBlank'; |
||||
import { InlineMonoText } from '../../components/Text'; |
||||
|
||||
const buildPeacefulStringTestBatch: BuildInputTestBatchFunction = ( |
||||
inputName, |
||||
onSuccess, |
||||
{ getValue } = {}, |
||||
onTestPeacefulStringFailureAppend, |
||||
) => ({ |
||||
defaults: { getValue, onSuccess }, |
||||
tests: [ |
||||
{ |
||||
onFailure: (...args) => { |
||||
onTestPeacefulStringFailureAppend( |
||||
<> |
||||
{inputName} cannot contain single-quote ( |
||||
<InlineMonoText text="'" /> |
||||
), double-quote (<InlineMonoText text='"' /> |
||||
), slash (<InlineMonoText text="/" /> |
||||
), backslash (<InlineMonoText text="\" /> |
||||
), angle brackets (<InlineMonoText text="<>" /> |
||||
), curly brackets (<InlineMonoText text="{}" /> |
||||
). |
||||
</>, |
||||
...args, |
||||
); |
||||
}, |
||||
test: ({ value }) => !/['"/\\><}{]/g.test(value as string), |
||||
}, |
||||
{ test: testNotBlank }, |
||||
], |
||||
}); |
||||
|
||||
export default buildPeacefulStringTestBatch; |
Loading…
Reference in new issue