[jina_validateip_9]
Description
Type that builds on the string -> validip method
Besides evaluating if a string is a valid IP number it can report back what parts of the string that's wrong. Made after a request from Chris Wik.
Needs the method string -> validip to work. Found here:
http://tagswap.net/validip_9/
Regular expression found here:
http://www.regular-expressions.info/examples.html
Parameters
none
Sample Usage
var(testips = array(
'192.168.2.55', // valid
'255.255.255.255', // valid
'0.0.0.0', // valid
'198.5.kk.25', // not valid
'198.5.4', // not valid
'999.999.255.255', // not valid
'my mother likes cakes' // not valid
))
var(holder = null)
iterate($testips)
$holder = jina_validateip
$holder -> input(loop_value)
$holder -> valid
!$holder -> valid ? ' ' + $holder -> errors
'<br>'
/iterate
Source Code
Click the "Download" button below to retrieve a copy of this tag,
including the complete documentation and sample usage shown
on this page. Place the downloaded ".inc" file in your
LassoStartup folder, restart Lasso, and you can begin using this
tag immediately.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?Lasso
/**!
Type that builds on the string -> validip method
Besides evaluating if a string is a valid IP number it can report back what parts of the string that's wrong. Made after a request from Chris Wik
Regular expression found here:
http://www.regular-expressions.info/examples.html
2010-11-08 Jolle Carlestam First version
Usage:
var(testips = array(
'192.168.2.55', // valid
'255.255.255.255', // valid
'0.0.0.0', // valid
'198.5.kk.25', // not valid
'198.5.4', // not valid
'999.999.255.255', // not valid
'my mother likes cakes' // not valid
))
var(holder = null)
iterate($testips)
$holder = jina_validateip
$holder -> input(loop_value)
$holder -> valid
!$holder -> valid ? ' ' + $holder -> errors
'<br>'
/iterate
*/
define jina_validateip => type {
data private err::array = array
data private valid = false
data private evaluated = false
data private input::string
public oncreate(
input::string = ''
) => {
.'input' = #input -> ascopy
.'input' -> size > 0 ? .evaluate
}
public oncreate(
-input::string
) => .oncreate(#input)
private evaluate() => {
.'valid' = .'input' -> validip
.'evaluated' = true
}
public input(input::string) => {.'input' = #input -> ascopy}
public valid() => {
fail_if(.'input' -> size == 0, -1, 'No input value provided')
if(!.'evaluated')
.evaluate
/if
return .'valid'
}
public asString() => .valid
public errors() => {
if(!.valid)
local('parts') = .'input' -> split('.')
#parts -> size != 4 ? .'err' -> insert('Not the right number of octets.')
local(reg_exp = regexp(-find = `\b(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b`))
iterate(#parts)
#reg_exp -> input = loop_value
(#reg_exp-> findall) -> size != 1 ? .'err' -> insert('Invalid character(s) in octet ' + loop_count + ': ' + loop_value)
/iterate
/if
return .'err'
}
public inputvalue() => .'input'
}
?>
Related Tags
Comments
none