Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
taobao-mini-template
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
qinhaitao
taobao-mini-template
Commits
14f45963
Commit
14f45963
authored
May 27, 2021
by
管新明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 调整validateRangeNumber方法校验
parent
8bbc3827
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
4 deletions
+15
-4
validate.js
client/utils/validate.js
+15
-4
No files found.
client/utils/validate.js
View file @
14f45963
...
@@ -28,15 +28,26 @@ export const isNumber = val => {
...
@@ -28,15 +28,26 @@ export const isNumber = val => {
* @returns { boolean }
* @returns { boolean }
*/
*/
export
const
validateRangeNumber
=
(
number
,
[
min
,
max
]
=
[],
fixed
=
0
)
=>
{
export
const
validateRangeNumber
=
(
number
,
[
min
,
max
]
=
[],
fixed
=
0
)
=>
{
const
pattern
=
new
RegExp
(
`^-?[0-9]+(\\.[0-9]{0,
${
fixed
}
})?$`
);
let
pattern
=
new
RegExp
(
`^[0-9]+(\\.[0-9]{1,
${
fixed
}
})?$`
);
// 判断空字符
if
(
typeof
number
===
'string'
&&
!
number
.
trim
())
return
false
if
(
fixed
===
0
||
!
number
.
includes
(
'.'
))
{
if
(
min
>
0
)
{
// 校验正整数
pattern
=
/^
[
1-9
]\d
*$/
}
else
if
(
min
===
0
)
{
// 校验自然数
pattern
=
/^
([
1-9
]\d
*|
[
0
]{1,1})
$/
}
}
if
(
min
>
max
)
{
if
(
min
>
max
)
{
console
.
error
(
'数字范围的最小值不能大于最大值'
);
console
.
error
(
'数字范围的最小值不能大于最大值'
);
return
;
return
;
}
}
if
(
number
!=
0
)
{
if
(
!
pattern
.
test
(
number
)
||
number
===
''
)
return
false
;
if
(
!
pattern
.
test
(
number
))
return
false
;
}
if
(
number
<
min
||
number
>
max
)
return
false
;
if
(
number
<
min
||
number
>
max
)
return
false
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment