discord-client/webpack/lib/field-manager.js

37 lines
1.2 KiB
JavaScript
Raw Normal View History

/* (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) => {
return typeof input === 'string' && input.trim() === input && /^[a-z0-9\. _-]{3,20}$/i.test(input);
}, '3 characters required: letters, numbers, spaces, dots, hyphens');
/* (3) URL name */
FieldValidator.pushFormat('url-name', (input) => {
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');
/* (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;
});