diff --git a/.changeset/little-pens-exist.md b/.changeset/little-pens-exist.md new file mode 100644 index 00000000000..37ef2047c7c --- /dev/null +++ b/.changeset/little-pens-exist.md @@ -0,0 +1,7 @@ +--- +"@wso2is/console": patch +"@wso2is/form": patch +"@wso2is/validation": patch +--- + +Update role name field input validation diff --git a/apps/console/src/features/roles/components/edit-role/edit-role-basic.tsx b/apps/console/src/features/roles/components/edit-role/edit-role-basic.tsx index 2655f732762..403460ec9f0 100644 --- a/apps/console/src/features/roles/components/edit-role/edit-role-basic.tsx +++ b/apps/console/src/features/roles/components/edit-role/edit-role-basic.tsx @@ -167,7 +167,7 @@ export const BasicRoleDetails: FunctionComponent = (props: Basic = (props: RoleBasicPr > { return false; } }; + +/** + * This validates the role name. Returns true if valid. False if not valid. + * + * @param value - Input to be validated. + * @returns whether input is accepted or not. + */ +export const isValidRoleName = (value: string): boolean => { + try { + const result: ValidationResult = Joi.string() + .regex(new RegExp("^[a-zA-Z][a-zA-Z0-9-_. ]+$")) + .min(3) + .max(255) + .validate(value); + + return !result.error; + } catch (error) { + return false; + } +};