Skip to content

Commit

Permalink
[ADDED] onpaste checking in username (#425)
Browse files Browse the repository at this point in the history
Signed-off-by: Zeeshan Mehboob <[email protected]>
  • Loading branch information
zesu22 authored Nov 14, 2024
1 parent 4935d62 commit a066bed
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions signup-ui/src/pages/ResetPasswordPage/UserInfo/UserInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
ChangeEvent,
ClipboardEvent,
KeyboardEvent,
MouseEvent,
useCallback,
Expand Down Expand Up @@ -122,6 +123,18 @@ export const UserInfo = ({ settings, methods }: UserInfoProps) => {
settings.response.configs["identifier.allowed.characters"]
);

// checking clipboard data with regex, before pasting it into the input field
const handleUsernamePaste = (event: ClipboardEvent<HTMLInputElement>) => {
const allowedCharsRegex = new RegExp(
settings.response.configs["identifier.allowed.characters"],
"g"
);

if (!allowedCharsRegex.test(event.clipboardData.getData("text/plain"))) {
event.preventDefault();
}
};

const handleFullNameInput = (
event: ChangeEvent<HTMLInputElement>,
field: ControllerRenderProps<FieldValues, "fullname">
Expand Down Expand Up @@ -278,6 +291,7 @@ export const UserInfo = ({ settings, methods }: UserInfoProps) => {
"identifier.length.max"
]
}
onPaste={handleUsernamePaste}
onKeyUp={handleUsernameInput}
onKeyDown={handleUsernameInput}
disabled={resendOtp}
Expand Down

0 comments on commit a066bed

Please sign in to comment.