Lasso Soft Inc. > Home

[Valid_Phone]

LinkValid_Phone
AuthorChris Corwin
CategoryUtility
Version8.x
LicensePublic Domain
Posted16 Nov 2005
Updated01 Feb 2008
More by this author...

Description

Returns (true|false) depending upon whether the input is valid or not. Has an optional -Strict parameter. I would also like to say: Hi Lasso Community.

Sample Usage

[//lasso

	local('somestrings' = 
			(:
				'(616) 555-1212',
				'(317) 418-1795',
				'317-418-1795',
				'(317)  418-1795',
				'(317)418-1795',
				'(317 418-1795',
				'(31) 418-1795',
				'(317) 4181795',
				'317 418 1795',
				'317-418-1795',
				'317418-1795',
				'317-418-1795',
				'(317418-1795',
				null,
				)
		);
	iterate(#somestrings, local('a_string'));
			'

'; 'Input'; ''#a_string''; '' Valid_Phone(#a_string, -Strict) ''; 'strict'; '

'; '

'; 'Input'; ''#a_string''; '' Valid_Phone(#a_string) ''; '

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

[//lasso

	define_tag(
		'Phone', 
		-namespace='Valid_',
		-priority='replace',
		-description='Returns (true|false) depending upon whether the input is valid or not. Has an optional -Strict parameter.',
		-Required='Input'
		);
			fail_if(
				!params->size,
				-1,
				'[Valid_Phone] requires a requires at least one parameter.'
			);
			
			local(
				'a_number' = string(#Input),
				'regex_Loose' = '^(\\(?\\d\\d\\d\\)?)?[ -]?\\d\\d\\d[ -]?\\d\\d\\d\\d$',
				'regex_Strict' = '^(\\(\\d\\d\\d\\) )?\\d\\d\\d[ -]\\d\\d\\d\\d$'
				);
			if: (params) >> -Strict;
					Local: 'a_regex' = @#regex_strict;
			else;
					Local: 'a_regex' = @#regex_loose;
			/if;
			return(boolean(string_FindRegExp( #a_number, -Find=#a_regex)->size));
	/define_tag;
]

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