Lasso Soft Inc. > Home

[jina_validateip_9]

Linkjina_validateip_9
AuthorJolle Carlestam
CategoryConditional
Version9.x
LicensePublic Domain
Posted08 Nov 2010
Updated08 Nov 2010
More by this author...

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

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
	'
' /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.

 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
	'
' /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

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft