Skip to content

Commit

Permalink
fix(users): fixed members name validation
Browse files Browse the repository at this point in the history
  • Loading branch information
serge1peshcoff committed May 13, 2020
1 parent 971d8dc commit 6179601
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions models/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const moment = require('moment');
const { Sequelize, sequelize } = require('../lib/sequelize');
const config = require('../config');

const NAME_REGEX = new RegExp('^[\\p{L} \\-\']*$', 'u');

const User = sequelize.define('user', {
username: {
type: Sequelize.STRING,
Expand Down Expand Up @@ -62,7 +64,7 @@ const User = sequelize.define('user', {
notEmpty: { msg: 'First name should be set.' },
notNull: { msg: 'First name should be set.' },
isValid(value) {
if (!new RegExp('^[\\p{L} -\']*$', 'u').test(value)) {
if (!NAME_REGEX.test(value)) {
throw new Error(`First name should only contain letters, spaces and dashes, got "${value}".`);
}
}
Expand All @@ -75,7 +77,7 @@ const User = sequelize.define('user', {
notEmpty: { msg: 'Last name should be set.' },
notNull: { msg: 'Last name should be set.' },
isValid(value) {
if (!new RegExp('^[\\p{L} -\']*$', 'u').test(value)) {
if (!NAME_REGEX.test(value)) {
throw new Error(`Last name should only contain letters, spaces and dashes, got "${value}".`);
}
}
Expand Down

0 comments on commit 6179601

Please sign in to comment.