2018-03-28 23:26:18 +00:00
|
|
|
/* (1) Init all
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Import field validator */
|
|
|
|
const fv = require('./field-validator.js');
|
|
|
|
|
|
|
|
/* (2) Create class easy access */
|
|
|
|
window.FieldValidator = fv.Class;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (1) Create basic validators
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) BYPASS */
|
|
|
|
FieldValidator.pushFormat('bypass', () => true);
|
|
|
|
|
|
|
|
/* (2) Basic name */
|
|
|
|
FieldValidator.pushFormat('basic-name', (input) => {
|
2018-03-29 11:14:37 +00:00
|
|
|
return typeof input === 'string' && input.trim() === input && /^[a-z0-9 _-]{3,20}$/i.test(input);
|
2018-03-28 23:26:18 +00:00
|
|
|
}, '3 characters required: letters, numbers, spaces, dots, hyphens');
|
|
|
|
|
|
|
|
/* (3) URL name */
|
|
|
|
FieldValidator.pushFormat('url-name', (input) => {
|
2018-03-29 11:14:37 +00:00
|
|
|
return typeof input === 'string' && input.trim() === input && /^[a-z0-9_-]{3,20}$/i.test(input);
|
2018-03-28 23:27:08 +00:00
|
|
|
}, '3 characters required: letters, numbers, hyphens');
|
2018-03-28 23:26:18 +00:00
|
|
|
|
|
|
|
/* (4) Password */
|
|
|
|
FieldValidator.pushFormat('password', (input) => {
|
|
|
|
return typeof input === 'string' && /^[^<>\/\\]{8,50}$/.test(input);
|
|
|
|
}, '8 characters required');
|
|
|
|
|
|
|
|
/* (5) Room type */
|
|
|
|
FieldValidator.pushFormat('room.type', (input) => {
|
|
|
|
return typeof input === 'string' && ['text', 'voice'].indexOf(input) > -1;
|
|
|
|
});
|
|
|
|
|
|
|
|
|