Skip to content

Commit

Permalink
fix: money format regex (#3913)
Browse files Browse the repository at this point in the history
* fix: money format regex

* test: money format
  • Loading branch information
hchlq authored Aug 4, 2023
1 parent da52e7c commit d37bce8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/validator/src/__tests__/validator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,12 @@ test('validate formats(phone)', async () => {
noError(await validate('15934567899', 'phone'))
})

test('validate formats(money)', async () => {
noError(await validate('$12', 'money'))
hasError(await validate('$12.', 'money'))
noError(await validate('$12.3', 'money'))
})

test('validate custom validator', async () => {
hasError(await validate('123', { custom: true }))
noError(await validate('', { custom: true }))
Expand Down
3 changes: 2 additions & 1 deletion packages/validator/src/formats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export default {

idcard: /^\d{15}$|^\d{17}(\d|x|X)$/,

money: /^([\u0024\u00A2\u00A3\u00A4\u20AC\u00A5\u20B1\u20B9\uFFE5]\s*)(\d+,?)+\.?\d*\s*$/,
money:
/^([\u0024\u00A2\u00A3\u00A4\u20AC\u00A5\u20B1\u20B9\uFFE5]\s*)(\d+,?)+(\.\d+)?\s*$/,

zh: /^[\u4e00-\u9fa5]+$/,

Expand Down

0 comments on commit d37bce8

Please sign in to comment.