Hey, let's play a small game all you have to do is fill all these text fileds. To help you,
you can read the rule that is implemented below.
Good luck!
xxxxxxxxxx
1
2const email = new Rule({
3 type: 'email',
4 domain: d => ['hotmail', 'outlook', 'gmail'].indexOf(d) !== -1,
5});
6
xxxxxxxxxx
1
2const PhoneNumber = new Rule({
3 type: 'string-int',
4 minLength: 10,
5 maxLength: 10,
6 match: /0(7|6).*/,
7})
8
xxxxxxxxxx
1
2const PassWord = new Rule({
3 type: 'password',
4 minLength: 8,
5 maxLength: 10,
6 matchesOneOf: ['@', '_', '-', '.', '?', '$'],
7 numbers: 1,
8 uppercase: 1,
9 });
10
xxxxxxxxxx
1
2const url = new Rule({
3 type: 'url',
4 domain: domain => domain === 'github.com',
5 protocol: protocol => protocol === 'https',
6});
7
xxxxxxxxxx
1
2const country = new Rule({
3 type: 'string',
4 oneOf: ['FR', 'US', 'EN'],
5});
6const zipcode = new Rule({
7 type: 'string-int',
8 minLength: 5,
9 maxLength: 5,
10});
11
12const street = new Rule({
13 type: 'string',
14 notEmpty: true,
15});
16
17const streetNumber = new Rule({
18 type: 'string-int',
19});
20
Last game.
Edit the code so that you have at least two valid tests!
xxxxxxxxxx
/*
Make any changments you want,
Your goal: get at least two valid tests
*/
const password = new Rule({
type: 'password',
minLength: 8,
maxLength: 10,
matchesOneOf: ['@', '_', '-', '.', '?', '$'],
numbers: 1,
uppercase: 1,
custom: val => val.split('-').length > 0,
});
password.test('change this code');
password.test('qwerty');