0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-06 20:40:08 -05:00

refactor(core): guard phone number with digital-only regex (#744)

This commit is contained in:
Xiao Yijun 2022-05-06 17:23:17 +08:00 committed by GitHub
parent 5909727ebc
commit 6ac70c5eb7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 6 deletions

View file

@ -1,3 +1,3 @@
// TODO - LOG-1876: Share Regex Between Logto Core and Front-End
export const emailRegEx = /^\S+@\S+\.\S+$/;
export const phoneRegEx = /^[1-9]\d{10}$/;
export const phoneRegEx = /^\d+$/;

View file

@ -556,10 +556,10 @@ describe('sessionRoutes', () => {
expect(response.statusCode).toEqual(400);
});
it('throw error if phone not valid (not exactly 11-digits)', async () => {
it('throw error if phone not valid (without digits)', async () => {
const response = await sessionRequest
.post('/session/register/passwordless/sms/send-passcode')
.send({ phone: '1300000000' });
.send({ phone: 'abcdefg' });
expect(response.statusCode).toEqual(400);
});
@ -596,10 +596,10 @@ describe('sessionRoutes', () => {
expect(response.statusCode).toEqual(400);
});
it('throw error if phone not valid (not exactly 11-digits)', async () => {
it('throw error if phone not valid (without digits)', async () => {
const response = await sessionRequest
.post('/session/register/passwordless/sms/verify-passcode')
.send({ phone: '1300000000', code: '1234' });
.send({ phone: 'abcdefg', code: '1234' });
expect(response.statusCode).toEqual(400);
});

View file

@ -1,5 +1,5 @@
export const emailRegEx = /^\S+@\S+\.\S+$/;
export const phoneRegEx = /^[1-9]\d{10}$/;
export const phoneRegEx = /^\d+$/;
export const usernameRegEx = /^.{3,}$/;
export const nameRegEx = /^.{3,}$/;
export const passwordRegEx = /^.{6,}$/;