[validip_9]

Description

Link: [validip_9]
Author: Jolle Carlestam
Category: Comparator
Version: 9.x
License: Public Domain
Posted: Nov. 07, 2010
Updated: Nov. 07, 2010
More by this author...

Extending the string type with a check to see if a string is a valid ip address. Will return true or false. Made after a request from Chris Wik
Regular expression found here:
http://www.regular-expressions.info/examples.html

Also as a method string_validip. The method will call string -> validip

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(output = array)

with i in $testips
do => {
	$output -> insert(string(#i) -> validip )

}

$output
						

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
<?Lasso
/**!
string -> validip
Extending the string type with a check to see if a string is a valid ip address. Will return true or false. 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(output = array)

with i in $testips
do => {
	$output -> insert(string(#i) -> validip )

}

$output

Lasso 9 -> array(true, true, true, false, false, false, false)

**/
define string -> validip() => ((regexp(-find = `\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b`, -input = self, -ignorecase)) -> findall) -> size == 1

/**!
jina_validip(string)
A method that checks if a string is a valid ip address. Will return true or false. Made after a request from Chris Wik

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(output = array)

with i in $testips
do => {
	$output -> insert(jina_validip(#i) )

}

$output

Lasso 9 -> array(true, true, true, false, false, false, false)

**/
define string_validip(input::string) => #input -> validip


?>

 

Related Tags



Comments

none

Email:


Password:



Newest

Most Popular

Support tagSwap.net