Skip to content

Commit

Permalink
fixed log type name validation
Browse files Browse the repository at this point in the history
Signed-off-by: Amardeepsingh Siglani <[email protected]>
  • Loading branch information
amsiglan committed Aug 2, 2023
1 parent abb2624 commit 6800c32
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion public/pages/LogTypes/components/LogTypeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const LogTypeForm: React.FC<LogTypeFormProps> = ({
const [nameError, setNameError] = useState('');

const updateErrors = (details = logTypeDetails) => {
const nameInvalid = !validateName(details.name, LOG_TYPE_NAME_REGEX);
const nameInvalid = !validateName(details.name, LOG_TYPE_NAME_REGEX, false /* shouldTrim */);
setNameError(nameInvalid ? 'Invalid name' : '');

return { nameInvalid };
Expand Down
9 changes: 7 additions & 2 deletions public/utils/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ export const AUTHOR_REGEX = new RegExp(/^[a-zA-Z0-9 _,-.]{5,50}$/);
* @param regex
* @return TRUE if valid; else FALSE.
*/
export function validateName(name: string, regex: RegExp = NAME_REGEX): boolean {
return name.trim().match(regex) !== null;
export function validateName(
name: string,
regex: RegExp = NAME_REGEX,
shouldTrimName: boolean = true
): boolean {
const toValidate = shouldTrimName ? name.trim() : name;
return toValidate.match(regex) !== null;
}

export function validateDetectionFieldName(
Expand Down

0 comments on commit 6800c32

Please sign in to comment.