omeralpi / shadcn-phone-input

Customizable phone input component with proper validation for any country. Built on top of shadcn.
https://shadcn-phone-input.vercel.app
MIT License
422 stars 28 forks source link

Server side zod schema #5

Closed fsiatama closed 5 months ago

fsiatama commented 6 months ago

Hello,

I've encountered an issue when using server actions with Next.js and attempting to validate phone numbers on the server side.

Currently, the documentation/code suggests using:

import { isValidPhoneNumber } from "react-phone-number-input";

However, this import is client-side oriented and might not be suitable for server-side validations due to its dependency on the react-phone-number-input package, which is primarily designed for client-side React applications.

For server-side validations within Next.js server actions, it's more appropriate to use:

import { isValidPhoneNumber } from 'libphonenumber-js';

omeralpi commented 5 months ago

@fsiatama I opened an issue in the React Phone Number Input repository.

And the creator of the package responded as follows:

Hmm, I see. Well, in that case just import the validation functions from libphonenumber-js package because all those functions are simply re-exported from that package.

libphonenumber-js package is a dependency of react-phone-number-input and is automatically installed.

ahkhanjani commented 5 months ago

Hi,

I think this could be mentioned in the readme for the time being.