-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Device Alias form has validation factors: (#813)
* Device Alias form validation has validation factors: - Max length of 30 characters - Name can not start with a space - Name should not contain special characters (only alphanumeric characters, underscore character, and hyphen or space in the middle are allowed) * Lint Formatting * Regex pattern explained. Better formatting and js logic
- Loading branch information
1 parent
463e2d3
commit 707142a
Showing
3 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export const validateAlias = ( | ||
{ | ||
valueMissing, | ||
patternMismatch, | ||
}: { valueMissing: boolean; patternMismatch: boolean }, | ||
value: string | ||
): string => { | ||
let message = ""; | ||
if (valueMissing) { | ||
message = "Please fill out this field."; | ||
} else if (patternMismatch) { | ||
if (value.startsWith(" ")) { | ||
message = "Name can't start with a space."; | ||
} else if ( | ||
value.endsWith(" ") || | ||
value.endsWith("-") || | ||
value.endsWith("_") | ||
) { | ||
message = "Name can't end with a space, hyphen or underscore."; | ||
} else { | ||
message = "Name can't contain special characters."; | ||
} | ||
} | ||
return message; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters