Skip to content

Commit f8c0589

Browse files
authoredJan 6, 2023
feat(util:format): support scientific notation of isNum (#1567)
1 parent d641164 commit f8c0589

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed
 

‎packages/util/form/validate.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ describe('utils: form-validate', () => {
1010
for (const item of data) {
1111
const ctr = new FormControl(item.k);
1212
const fn = _Validators[methodName] as (control: AbstractControl) => ValidationErrors | null;
13+
const res = fn(ctr);
1314
if (item.v) {
14-
expect(fn(ctr)).toBeNull();
15+
expect(res).toBeNull();
1516
} else {
16-
const res = fn(ctr);
1717
expect(res).not.toBeNull();
1818
expect((res as NzSafeAny)[methodName]).toEqual(true);
1919
}

‎packages/util/format/validate.spec.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ export const TEST_DATA = {
1010
{ k: '-12', v: true },
1111
{ k: 123, v: true },
1212
{ k: '123.1.2', v: false },
13-
{ k: '123a', v: false }
13+
{ k: '123a', v: false },
14+
{ k: '1.123e-10', v: true },
15+
{ k: '+1.123e-10', v: true },
16+
{ k: '+.1e-1', v: true },
17+
{ k: '1.0e+1', v: true },
18+
{ k: '1.0e+', v: false }
1419
],
1520
int: [
1621
{ k: '123', v: true },

‎packages/util/format/validate.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const REGEX_STR = {
2-
num: `((-?\\d+\\.\\d+)|(-?\\d+)|(-?\\.\\d+))`,
2+
num: `(([-+]?\\d+\\.\\d+)|([-+]?\\d+)|([-+]?\\.\\d+))(?:[eE]([-+]?\\d+))?`,
33
idCard: `(^\\d{15}$)|(^\\d{17}(?:[0-9]|X)$)`,
44
mobile: `^(0|\\+?86|17951)?1[0-9]{10}$`,
55
url: `(((^https?:(?:\/\/)?)(?:[-;:&=\\+\\$,\\w]+@)?[A-Za-z0-9.-]+(?::\\d+)?|(?:www.|[-;:&=\\+\\$,\\w]+@)[A-Za-z0-9.-]+)((?:\/[\\+~%\\/.\\w-_]*)?\\??(?:[-\\+=&;%@.\\w_]*)#?(?:[\\w]*))?)`,

0 commit comments

Comments
 (0)
Please sign in to comment.