Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
osticket
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
docker
osticket
Commits
75ac396e
Commit
75ac396e
authored
11 years ago
by
Jared Hancock
Browse files
Options
Downloads
Patches
Plain Diff
Add a minimum validation to the 'int' type
parent
9549fba1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/class.validator.php
+15
-13
15 additions, 13 deletions
include/class.validator.php
with
15 additions
and
13 deletions
include/class.validator.php
+
15
−
13
View file @
75ac396e
...
...
@@ -3,7 +3,7 @@
class.validator.php
Input validation helper. This class contains collection of functions used for data validation.
Peter Rotich <peter@osticket.com>
Copyright (c) 2006-2013 osTicket
http://www.osticket.com
...
...
@@ -28,11 +28,11 @@ class Validator {
$this
->
fields
=
$fields
;
return
(
true
);
endif
;
return
(
false
);
}
function
validate
(
$source
,
$userinput
=
true
){
$this
->
errors
=
array
();
...
...
@@ -56,7 +56,7 @@ class Validator {
foreach
(
$this
->
fields
as
$k
=>
$field
){
if
(
!
$field
[
'required'
]
&&
!
$this
->
input
[
$k
])
//NOT required...and no data provided...
continue
;
if
(
$field
[
'required'
]
&&
!
isset
(
$this
->
input
[
$k
])
||
(
!
$this
->
input
[
$k
]
&&
$field
[
'type'
]
!=
'int'
)){
//Required...and no data provided...
$this
->
errors
[
$k
]
=
$field
[
'error'
];
continue
;
...
...
@@ -67,7 +67,9 @@ class Validator {
case
'int'
:
if
(
!
is_numeric
(
$this
->
input
[
$k
]))
$this
->
errors
[
$k
]
=
$field
[
'error'
];
break
;
elseif
(
$field
[
'min'
]
&&
$this
->
input
[
$k
]
<
$field
[
'min'
])
$this
->
errors
[
$k
]
=
$field
[
'error'
];
break
;
case
'double'
:
if
(
!
is_numeric
(
$this
->
input
[
$k
]))
$this
->
errors
[
$k
]
=
$field
[
'error'
];
...
...
@@ -114,7 +116,7 @@ class Validator {
break
;
case
'zipcode'
:
if
(
!
is_numeric
(
$this
->
input
[
$k
])
||
(
strlen
(
$this
->
input
[
$k
])
!=
5
))
$this
->
errors
[
$k
]
=
$field
[
'error'
];
$this
->
errors
[
$k
]
=
$field
[
'error'
];
break
;
default
://
If
param
type
is
not
set
...
or
handle
..
error
out
...
$this
->
errors
[
$k
]
=
$field
[
'error'
]
.
' (type not set)'
;
...
...
@@ -122,15 +124,15 @@ class Validator {
}
return
(
$this
->
errors
)
?
(
FALSE
)
:
(
TRUE
);
}
function
iserror
(){
return
$this
->
errors
?
true
:
false
;
}
function
errors
(){
return
$this
->
errors
;
}
/*** Functions below can be called directly without class instance. Validator::func(var..); ***/
function
is_email
(
$email
)
{
return
preg_match
(
'/^([*+!.&#$|\'\\%\/0-9a-z^_`{}=?~:-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})$/i'
,
$email
);
...
...
@@ -140,17 +142,17 @@ class Validator {
$stripped
=
preg_replace
(
"(\(|\)|\-|\.|\+|[ ]+)"
,
""
,
$phone
);
return
(
!
is_numeric
(
$stripped
)
||
((
strlen
(
$stripped
)
<
7
)
||
(
strlen
(
$stripped
)
>
16
)))
?
false
:
true
;
}
function
is_url
(
$url
)
{
//XXX: parse_url is not ideal for validating urls but it's ideal for basic checks.
return
(
$url
&&
(
$info
=
parse_url
(
$url
))
&&
$info
[
'host'
]);
}
function
is_ip
(
$ip
)
{
if
(
!
$ip
or
empty
(
$ip
))
return
false
;
$ip
=
trim
(
$ip
);
# Thanks to http://stackoverflow.com/a/1934546
if
(
function_exists
(
'inet_pton'
))
{
# PHP 5.1.0
...
...
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