[Valid_Phone]

Description

Link: [Valid_Phone]
Author: Chris Corwin
Category: Utility
Version: 8.x
License: Public Domain
Posted: Nov. 16, 2005
Updated: Feb. 01, 2008
More by this author...
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.

Parameters

-Input string, required The phone number to be checked for validness.
-Strict string, optional Determines how strictly to judge the phone number for validness.

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'));
			'<p>';
					'<var>Input</var>';
					'<samp>'#a_string'</samp>';
					'<em>' Valid_Phone(#a_string, -Strict) '</em>';
					'<dfn>strict</dfn>';
			'</p>';
			'<p>';
					'<var>Input</var>';
					'<samp>'#a_string'</samp>';
					'<em>' Valid_Phone(#a_string) '</em>';
			'</p>';
	/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
[//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

none

Email:


Password:



Newest

Most Popular