Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
Book-Management-System
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ashwanth K
Book-Management-System
Commits
44843ea8
Commit
44843ea8
authored
4 years ago
by
Ashwanth K
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
795c2204
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
client/src/Shared/validator.js
+98
-0
98 additions, 0 deletions
client/src/Shared/validator.js
with
98 additions
and
0 deletions
client/src/Shared/validator.js
0 → 100644
+
98
−
0
View file @
44843ea8
/**
* Chek if email is valid
* @prop String email
* @returns Boolean
*/
export
const
isEmail
=
(
email
)
=>
{
const
re
=
/^
(([^
<>()[
\]\\
.,;:
\s
@"
]
+
(\.[^
<>()[
\]\\
.,;:
\s
@"
]
+
)
*
)
|
(
".+"
))
@
((\[[
0-9
]{1,3}\.[
0-9
]{1,3}\.[
0-9
]{1,3}\.[
0-9
]{1,3}\])
|
(([
a-zA-Z
\-
0-9
]
+
\.)
+
[
a-zA-Z
]{2,}))
$/
;
return
re
.
test
(
email
);
}
/**
* Chek if vatiable is empty
* @prop String thing
* @returns Boolean
*/
export
const
isEmpty
=
(
thing
)
=>
{
let
empty
=
false
;
switch
(
typeof
thing
)
{
case
'
undefined
'
:
empty
=
true
;
break
;
case
'
string
'
:
if
(
thing
.
trim
().
length
===
0
)
{
empty
=
true
;
}
break
;
case
'
object
'
:
if
(
thing
===
null
)
{
empty
=
true
;
}
else
if
(
Object
.
keys
(
thing
).
length
===
0
)
{
empty
=
true
;
}
break
;
default
:
empty
=
true
;
}
return
empty
;
}
/**
* Check length of the string greater than
* @prop String|Integer str
* @prop boolean|options.trim Trim input before validating
* @prop number|options.lt Check if length less than lt
* @prop number|options.lte Check if length is less than or equals to lte
* @prop number|options.gt Check if length is greater than gt
* @prop number|options.gte Check if length is greater than or equals to gte
* @returns Boolean
*/
export
const
isLength
=
(
str
,
options
)
=>
{
if
(
isEmpty
(
options
))
{
throw
new
Error
(
"
Who will provide the options you?
"
)
}
let
isValid
=
true
;
if
([
'
string
'
,
'
number
'
].
indexOf
(
typeof
str
)
===
-
1
)
{
isValid
=
false
;
}
else
{
// Convert to string incase it's number
let
len
=
0
;
if
(
options
.
trim
){
len
=
str
.
toString
().
trim
().
length
;
}
else
{
len
=
str
.
toString
().
length
;
}
if
(
typeof
options
.
lt
===
'
number
'
&&
len
>=
options
.
lt
)
{
isValid
=
false
;
}
else
if
(
typeof
options
.
lte
===
'
number
'
&&
len
>
options
.
lte
)
{
isValid
=
false
;
}
else
if
(
typeof
options
.
gt
===
'
number
'
&&
len
<=
options
.
gt
)
{
isValid
=
false
;
}
else
if
(
typeof
options
.
gte
===
'
number
'
&&
len
<
options
.
gte
)
{
isValid
=
false
;
}
}
return
isValid
;
}
/**
* Check if string contains whitespaces
* @prop String str
* @returns Boolean
*/
export
const
isContainWhiteSpace
=
(
str
)
=>
{
if
(
typeof
str
===
'
string
'
||
typeof
str
===
'
number
'
){
return
str
.
toString
().
trim
().
indexOf
(
'
'
)
!==
-
1
;
}
else
{
return
false
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment