Skip to content

Commit

Permalink
Add regex to constant
Browse files Browse the repository at this point in the history
  • Loading branch information
Tostti committed Dec 21, 2022
1 parent 0a341f1 commit c818603
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions public/controllers/agent/components/register-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,14 @@ export const RegisterAgent = withErrorBoundary(
}

setAgentName(event) {
const validation = /^[a-z0-9-_.]+$/i;
this.setState({ agentName: event.target.value });
if (/^[a-z0-9-_.]+$/i.test(event.target.value) || event.target.value.length <= 0) {
if (validation.test(event.target.value) || event.target.value.length <= 0) {
this.setState({ agentNameError: false });
this.setState({ badCharacters: [] });
} else {
let badCharacters = event.target.value.split('').map(char =>
char.replace(/^[a-z0-9-_.]+$/i, '')).join('');
char.replace(validation, '')).join('');
badCharacters = badCharacters.split('').map(char =>
char.replace(/\s/, 'whitespace'));
const characters = [...new Set(badCharacters)];
Expand Down

0 comments on commit c818603

Please sign in to comment.