validatorjs / validator.js

String validation
MIT License
23.12k stars 2.31k forks source link

validator.isNumeric inconsistent execution results #1079

Closed MayRain1999 closed 5 years ago

MayRain1999 commented 5 years ago

The first number is pasted into the code.second and third number is manually entered. Inconsistent execution results

 console.log("validator.isNumeric('6613476279‬')",validator.isNumeric("6613476279‬"))
 console.log("validator.isNumeric('123212131')",validator.isNumeric("123212131"))
 console.log("validator.isNumeric('6613476279‬')",validator.isNumeric('6613476279'))
validator.isNumeric('6613476279‬') false
validator.isNumeric('123212131') true
validator.isNumeric('6613476279‬') true
node-version:  10.16.2 ,
validator: 10.11.0,
profnandaa commented 5 years ago

@ezrqnkemboi -- can investigate this please?

ezkemboi commented 5 years ago

Yes, will do that @profnandaa. Will get some feedback on the results.

ezkemboi commented 5 years ago

I have done my research on this and found that the issue is about copying and pasting. When pasting, it seems that there is a whitespace/weird character created at the end of the numeric. For instance in this code:

console.log("validator.isNumeric('6613476279‬')",validator.isNumeric("6613476279‬"))

If you paste somewhere this code, then try a backspace/delete from the end of number 9, instead of removing digit 9, it will remove the whitespace or weird character. Then, when you run the code, it will finally return true.

Thus, from my research, I can conclude that:

Someone else can add their thoughts. But, if all parties are satisfied, then the issue can be closed.

cc @profnandaa and @xiaopingzhang0207

profnandaa commented 5 years ago

Could you running it through trim before checking .isNumeric?

-na

On Sun, Aug 18, 2019 at 11:27 PM Ezrqn Kemboi notifications@github.com wrote:

I have done my research on this and found that the issue is about copying and pasting. When pasting, it seems that there is a whitespace/weird character created at the end of the numeric. For instance in this code:

console.log("validator.isNumeric('6613476279‬')",validator.isNumeric("6613476279‬"))

If you paste somewhere this code, then try a backspace/delete from the end of number 9, instead of removing digit 9, it will remove the whitespace or weird character. Then, when you run the code, it will finally return true.

Thus, from my research, I can conclude that:

  • Copy-pasting items sometimes might bring unnecessary characters.
  • This is not a bug (It is a created bug from pasting).
  • When we try to solve the issue of pasting digits, it might validate unnecessary characters, which are not digits.

Someone else can add their thoughts. But, if all parties are satisfied, then the issue can be closed.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/validatorjs/validator.js/issues/1079?email_source=notifications&email_token=AAB7ZEPCNL2FOKYPLVPBAA3QFGWCNA5CNFSM4IKS3AX2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4RHQIA#issuecomment-522352672, or mute the thread https://github.com/notifications/unsubscribe-auth/AAB7ZEK7R3D5MIKU4PCNCYDQFGWCNANCNFSM4IKS3AXQ .

--

*___Nandaa *Anthony ,Software Craftsman & Mentor Twitter/Github: @profnandaa https://twitter.com/profnandaa

ezkemboi commented 5 years ago

Alright @profnandaa, I will do that and get back.

ezkemboi commented 5 years ago

Could you running it through trim before checking .isNumeric? -na On Sun, Aug 18, 2019 at 11:27 PM Ezrqn Kemboi @.> wrote: I have done my research on this and found that the issue is about copying and pasting. When pasting, it seems that there is a whitespace/weird character created at the end of the numeric. For instance in this code: console.log("validator.isNumeric('6613476279‬')",validator.isNumeric("6613476279‬")) If you paste somewhere this code, then try a backspace/delete from the end of number 9, instead of removing digit 9, it will remove the whitespace or weird character. Then, when you run the code, it will finally return true. Thus, from my research, I can conclude that: - Copy-pasting items sometimes might bring unnecessary characters. - This is not a bug (It is a created bug from pasting). - When we try to solve the issue of pasting digits, it might validate unnecessary characters, which are not digits. Someone else can add their thoughts. But, if all parties are satisfied, then the issue can be closed. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#1079?email_source=notifications&email_token=AAB7ZEPCNL2FOKYPLVPBAA3QFGWCNA5CNFSM4IKS3AX2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4RHQIA#issuecomment-522352672>, or mute the thread https://github.com/notifications/unsubscribe-auth/AAB7ZEK7R3D5MIKU4PCNCYDQFGWCNANCNFSM4IKS3AXQ . -- ___Nandaa Anthony ,Software Craftsman & Mentor Twitter/Github: *@profnandaa https://twitter.com/profnandaa

I have tried trim but does not work.

MayRain1999 commented 5 years ago

Thank you for your answer.