Giter Club home page Giter Club logo

yup-phone's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

yup-phone's Issues

An in-range update of husky is breaking the build 🚨

The devDependency husky was updated from 2.5.0 to 2.6.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

husky is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Commits

The new version differs by 9 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

yup-phone is not working with yup latest version (1.2.0)

Describe the bug
yup-phone is not working with this current version

getting: TypeError: yup__WEBPACK_IMPORTED_MODULE_5__.string(...).phone is not a function

To Reproduce
Try to validate phone number with yup-phone

const validate = Yup.object({
phone: Yup.string()
.phone("IN")
.required('Enter your valid mobile number.'),
})

NOTE: if you do not provide a runnable reproduction the chances of getting feedback are significantly lower

Expected behavior
Should validate the phone input field

Platform (please complete the following information):

Browser [All]
Version [latest]
Additional context

"next": "13.4.9",
"react": "18.2.0",
"react-dom": "18.2.0",
"formik": "^2.4.2",
"yup": "^1.2.0",
"yup-phone": "^1.3.2"

An in-range update of rollup is breaking the build 🚨

The devDependency rollup was updated from 1.14.2 to 1.14.3.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

rollup is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for v1.14.3

2019-06-06

Bug Fixes

  • Generate correct external imports when importing from a directory that would be above the root of the current working directory (#2902)

Pull Requests

Commits

The new version differs by 4 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Passing Undefined To Country Code Causes Unexpected Behaviour - Non-Strict Mode Unclear

Hey there!

Thanks for making this!

I'm calling this library with the following.

.phone(undefined, false, "A valid phone number is required")

This code is valid, because the type signature is as follows https://github.com/abhisekp/yup-phone/blob/master/src/yup-phone.ts#L16 - the first parameter is not required.

However, the library defaults to India in this case running the following:

const phoneNumber = phoneUtil.parseAndKeepRawInput(value, 'IN');

When we do the following:

const regionCodeFromPhoneNumber = phoneUtil.getRegionCodeForNumber(
    phoneNumber
);

Therefore we always get IN back in this situation, because the phone number of an unknown validity has been parsed as belonging to this region.

If the intended behaviour is that when we are not in strict mode, then the phone number's region is derived from the phone number itself then validated, then it will always be validated with the region specified or India.

So it is never really a "unstrict" test for any valid global phone number. It always needs a region.

Google's guide suggests that isValidNumberForRegion should be used sparing https://github.com/google/libphonenumber/blob/master/FAQ.md#when-should-i-use-isvalidnumberforregion

Maybe when we aren't in strict mode then isValidNumber() could be used?

Maybe I am missing something here?

In a PHP version of this library, one can pass empty strings or null when the region is unknown when parsing.

giggsey/libphonenumber-for-php#85

This however is not valid code:

const phoneUtil = require('google-libphonenumber').PhoneNumberUtil.getInstance();

const value = '202-456-1414';
const phoneNumber = phoneUtil.parse(value);

In the other Javascript library port of libphonenumber, this is valid code:

const parsePhoneNumber = require('libphonenumber-js');

const phoneNumber = parsePhoneNumber('+1 202-456-1414');

phoneNumber.isValid();

Hope this isn't confusing!

Custom Error Message

How to make a custom error message ?

I tried something like this :

phoneNumber: Yup.string().phone(errorMessage="Please enter a valid phone number, include the country and area codes."),

But it does not work.

An in-range update of @types/jest is breaking the build 🚨

The devDependency @types/jest was updated from 24.0.16 to 24.0.17.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@types/jest is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • now: Deployment has failed (error: #IIOglIm) (Details).
  • continuous-integration/travis-ci/push: The Travis CI build passed (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Locale Validation not correct?

First of all thanks for creating this!

I guess this is more of a question than an issue, although the answer will indicate whether it's a bug or not.

My understanding would be if you tried to validate a number with a specific locale using a different country code, that it would return false.

e.g. given
const phoneSchemaDE = yup.string().phone('DE');

I would expect the following to return false, as the country code is not DE:
phoneSchemaDE.isValidSync('+919876543210');
but it doesn't, it returns true.

So my ultimate quesiton is,
is the locale check:
"is this number a valid phone number when calling FROM this country?"
or
"is this number a valid number FOR this country?"

Bundle Size

Whilst this project is amazing and should be included out of the box as a Yup rule, I can't help but notice the huge bundle size, see:

image

Could you please consider refactoring and improving the code so that it gets reflected in the bundle size? 🙏

Breaks output typescript types

When using this package, we are getting an odd typescript error after transpilation. tsc completes successfully, but the "output" .d.ts files this error:

Namespace "yup" has no exported member 'default' in output

I believe this might have something to do with this package importing an old version of "@types/yup": "^0.29.13",. It seems like the most recent version of yup is actually written in typescript (or at least provides it's own types), so this shouldn't be necessary.

Overrides yup's required() error message when no value is present.

Here is a snippet from my yup validation schema. I would like to pass a message into the required function to display something user-friendly if they don't enter any text.

emergencyPhoneNumber: Yup.string()
  .phone()
  .required('Emergency contact phone number is required.'),

I know I can provide a custom error message through phone() however, as this is an add-on to yup, it should support yup's expected behavior. If possible, I would like to be able to provide an error message for when a user input's an invalid phone number and a required message if they don't input anything.

Always False when value is undefined

I am using Yup-phone & Yup on a react project to validate data of formik forms, but my phone field is not mandatory and could have a value undefined.

Using yup phone, when my phone field is undefined, Yup always considers it as an error but it is wrong. Reading the code, we should consider that value could be undefined, so the test does not fail.

That is an example of phone implement you could consider :

Yup.addMethod(Yup.string, 'phone', function (countryCode?: string, strict = false, errorMessage = '') {
  const errMsg =
    typeof errorMessage === 'string' && errorMessage
      ? errorMessage
      : isValidCountryCode(countryCode)
      ? `\${path} must be a valid phone number for region ${countryCode}`
      : '${path} must be a valid phone number.'

  return this.test('phone', errMsg, (value?: string) => {
    let _countryCode = countryCode
    let _strict = strict
    if (!isValidCountryCode(countryCode)) {
      // if not valid countryCode, then set default country to India (IN)
      _countryCode = 'IN'
      _strict = false
    }

    try {
      if (value) {
        const phoneNumber = phoneUtil.parseAndKeepRawInput(value, countryCode)

        if (!phoneUtil.isPossibleNumber(phoneNumber)) {
          return false
        }

        const regionCodeFromPhoneNumber = phoneUtil.getRegionCodeForNumber(phoneNumber)

        /* check if the countryCode provided should be used as default country code or strictly followed */
        return _strict ? phoneUtil.isValidNumberForRegion(phoneNumber, _countryCode) : phoneUtil.isValidNumberForRegion(phoneNumber, regionCodeFromPhoneNumber)
      }
      return true
    } catch {
      return false
    }
  })
})

Here is an example of my usage:

export const userFormSchema = Yup.object().shape({
  lastname: Yup.string().required('error.fieldRequired'),
  firstname: Yup.string().required('error.fieldRequired'),
  email: Yup.string().email('error.invalidMail').required('error.fieldRequired'),
  mobile: Yup.string().phone('fr', undefined, 'error.invalidPhone').required('required'),
  office: Yup.string().phone('fr', undefined, 'error.invalidPhone').optional(),
})

Thanks to my previous proposal, I have no error when phone is not mandatory (ie undefined)

Wrong validation result on some countries

Did not expect alphabets & special characters should be valid for Germany phone number.

yup.string().phone('DE', false, 'it's wrong').isValidSync('619490ac8@')

(also tested the underlying google-libphonenumber, consistent results... so I assume it's not our fault on this side 🥲)


(p.s. would be nice if the doc could forward us to somewhere to find the list of supported countryCodes)

TypeError: (0 , _yup.string)(...).phone is not a function

Hi,

Today I updated yup-phone to last version. Then one of my validators stops working and I got the following error:

C:\Users\User\Documents\Momento\development\Wallet\apis\transactions\src\validators\createUserValidators.js:42
const phoneSchema = (0, _yup.string)().phone('US', true).required();
                                       ^

TypeError: (0 , _yup.string)(...).phone is not a function
    at Object.<anonymous> (C:\Users\User\Documents\Momento\development\Wallet\apis\transactions\src\validators\/createUserValidators.js:37:37)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Module._compile (C:\Users\User\Documents\Momento\development\Wallet\apis\transactions\node_modules\pirates\lib\index.js:99:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Object.newLoader [as .js] (C:\Users\User\Documents\Momento\development\Wallet\apis\transactions\node_modules\pirates\lib\index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Module.require (internal/modules/cjs/loader.js:1025:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (C:\Users\User\Documents\Momento\development\Wallet\apis\transactions\src\resolvers\users\/CreateUser.js:6:1)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Module._compile (C:\Users\User\Documents\Momento\development\Wallet\apis\transactions\node_modules\pirates\lib\index.js:99:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Object.newLoader [as .js] (C:\Users\User\Documents\Momento\development\Wallet\apis\transactions\node_modules\pirates\lib\index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
[nodemon] app crashed - waiting for file changes before starting...

I went back to version 1.2.12 and the issue went away.

Hope you can help me. Regards!

Leonel

Add message to validation

Hello,

Thanks a lot for this tool, it seems very useful.

I am new to Yup and I am using it for the first time together with Formik.

I would like to customize the error message that is displayed in my form when an incorrect phone number is entered.

At the moment it says: "[...input] must be a valid phone number."

I am using it like this:
Yup.string().phone().required()

When i hover over required() I get required(message?: Yup.TestOptionsMessage<{}, any>): Yup.StringSchema<string>

I would very much like to add a message to the phone also but here i get: phone(countryCode?: string, strict?: boolean): Yup.StringSchema<string>

I am not familiar with TypeScript yet so I don't think I will give a PR a go, but is this something you could implement?

Property 'string' does not exist on type 'typeof import("yup")'

I get the following TypeScript error. It appears that the types in this repo overwrite the @types/yup ones

import * as Yup from 'yup';
import '@abhisekp/yup-phone';

export default Yup.object().shape({
  emailAddress: Yup.string()
    .email('Email is not a valid email address')
    .required('Email is required'),
});

An in-range update of babel7 is breaking the build 🚨

There have been updates to the babel7 monorepo:

    • The devDependency @babel/core was updated from 7.5.5 to 7.6.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

This monorepo update includes releases of one or more dependencies which all belong to the babel7 group definition.

babel7 is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • Tidelift: Failed dependency checks (Details).
  • continuous-integration/travis-ci/push: The Travis CI build passed (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of babel7 is breaking the build 🚨

There have been updates to the babel7 monorepo:

    • The devDependency @babel/core was updated from 7.5.5 to 7.6.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

This monorepo update includes releases of one or more dependencies which all belong to the babel7 group definition.

babel7 is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build passed (Details).
  • Tidelift: Failed dependency checks (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of google-libphonenumber is breaking the build 🚨

The dependency google-libphonenumber was updated from 3.2.4 to 3.2.5.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

google-libphonenumber is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • Tidelift: Dependencies checked (Details).
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Commits

The new version differs by 3 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Broken on yup 1.0.0.

Hello,
since updateing to yup 1.0.0 I get the following error message

 ERROR(vue-tsc)  Property 'phone' does not exist on type 'StringSchema<string | undefined, AnyObject, undefined, "">'.
 FILE  /Users/mariojacobi/Repositories/sofi-landing-page/pages/group/[id].vue:194:40

    192 |     vibe: yup.string().required(),
    193 |     phoneNumber: yup.string().test('test-phone', "This phone number doesn't seem to look valid", (value) => {
  > 194 |       if (value) { return yup.string().phone().isValidSync(value) }
        |                                        ^^^^^
    195 |       return true
    196 |     })
    197 |   })

Does anybody have a solution yet?

How to set phone as required phone number in a conditional?

  • yup: 0.32.9
  • yup-phone: 1.2.19

Given some yup schema, I expect these validations (codesandbox tests)

  1. invalid
{ email: '[email protected]', phone: '1' } // valid email, invalid phone
  1. invalid
{ email: 'a', phone: '08012341234' } // invalid email, valid phone (japan)
  1. validate
{ email: '', phone: '08012341234' } // empty email, valid phone (japan)
  1. validate
{ email: '[email protected]', phone: '' } // valid email, empty phone
  1. validate
{ email: '[email protected]', phone: '08012341234' } // valid email, valid phone (japan)

I've tried these test cases with two different schemas

1

yup.object().shape(
  {
    email: yup
      .string()
      .email()
      .when("phone", {
        is: (val) => !val || val.length < 1,
        then: yup.string().email().required(),
        otherwise: yup.string().email()
      }),
    phone: yup
      .string()
      .phone()
      .when("email", {
        is: (val) => !val || val.length < 1,
        then: yup.string().phone().required(),
        otherwise: yup.string()
      })
  },
  [["email", "phone"]]
);

2

yup.object().shape(
  {
    email: yup
      .string()
      .email()
      .when("phone", {
        is: (val) => !val || val.length < 1,
        then: yup.string().email().required(),
        otherwise: yup.string().email()
      }),
-   phone: yup.string().phone().when("email", {
+   phone: yup.string().when("email", {
      is: (val) => !val || val.length < 1,
      then: yup.string().phone().required(),
      otherwise: yup.string()
    })
  },
  [["email", "phone"]]
);

I'm struggling to get all the tests to pass. What is the correct schema to use so that

  • valid email + invalid phone = invalidation
  • invalid email + valid phone = invalidation
  • empty email + valid phone = validation
  • valid email + empty phone = validation
  • valid email + valid phone = validation

related to jquense/yup#79 (comment)

TypeError: yup__WEBPACK_IMPORTED_MODULE_4__.string(...).phone is not a function

In registration page, I'm using:

import * as Yup from "yup";
import "yup-phone";

Then setting RegistrationSchema as follows:

const RegistrationSchema = Yup.object().shape({
    first_name: Yup.string()
      .required(),
    last_name: Yup.string()
      .required(),
    email: Yup.string()
      .email("Wrong email format")
      .required(),
    phone: Yup.string()
      .phone()
      .required()
  });

But getting this error:

TypeError: yup__WEBPACK_IMPORTED_MODULE_4__.string(...).phone is not a function

I'm working on a new admin theme and fairly new to this. Kindly advice.

Thanks

EDIT: Nevermind, the new version 1.2.4 resolved it 👍

Release to NPM

@abhisekp Are you able to release this package to NPM so we can use it? :) Thanks for the cool package.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.