-
Notifications
You must be signed in to change notification settings - Fork 14
Validate phone numbers #92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Hello there @arisGio ! Thanks once again for the contribution!!!! I have created an issue but I also cannot assign you on it!!!! I'll have to check this article and hopefully will find a way to fix this... In the mean time I'll have a small suggestion (for consistency - I'll leave it as a code review). |
src/validationUtils.ts
Outdated
*/ | ||
export function isValidMobilePhone(mobilePhone: string): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also support numbers as well (for this and all the other phone related fns)? It is not a big change, just a minor check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
However, when updating the test cases I saw that numbers starting with 00 are not acceptable by the linter so did not add them to the tests.
src/validationUtils.ts
Outdated
const mobilePhoneRegex = RegExp(/^(\+30|0030)?69\d{8}$/); | ||
|
||
return mobilePhoneRegex.test(mobilePhone.replace(/[\s\-().]/g, "")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep it as simple as possible.
const mobilePhoneRegex = RegExp(/^(\+30|0030)?69\d{8}$/); | |
return mobilePhoneRegex.test(mobilePhone.replace(/[\s\-().]/g, "")); | |
let mobilePhoneStr = mobilePhone; | |
if (typeof mobilePhone === "number") { | |
mobilePhoneStr = String(num).slice(-10) | |
} | |
const mobilePhoneRegex = RegExp(/^(\+30|0030)?69\d{8}$/); | |
return mobilePhoneRegex.test(mobilePhoneStr.replace(/[\s\-().]/g, "")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @tsevdos!
Numbers starting with 2 zeros are not accepted at all.
Since either way we use string type to apply logic for each method then I decided first things first to convert to string using the respective constructor.
Removed any RegExp constructors to simplify code even further and kept it only in the case of any template literals.
|
Uh oh!
There was an error while loading. Please reload this page.