[jina_validatephone]

Description

Link: [jina_validatephone]
Author: Jolle Carlestam
Category: Utility
Version: 9.x
License: Public Domain
Posted: Aug. 12, 2010
Updated: Aug. 12, 2010
More by this author...

Exercise in writing a type that uses regexp to validate that a phone number only contains approved characters. Such as digits or any of +, -, space, ., (,) Can return true or false, the errors found etc. Can also clean the input from all non-approved chars. Written by Jolle Carlestam in an iterative process with Chris Wik, Ke Carlton and Tim Taplin after a discussion on the Lasso 9 beta list 2010-08-12

Parameters

none


Sample Usage

local('test_num' = jina_validatephone('1-970-728-9773'));
#test_num -> valid;
#test_num; // Returns true or false, same as using jina_validatephone -> valid
#test_num -> errors;
#test_num -> findvalue;
#test_num -> inputvalue;
#test_num -> cleanup;
						

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
<?LassoScript
/**!
Exercise in writing a type that uses regexp to validate that a phone number only contains approved characters. Such as digits or any of +, -, space, ., (,)
Can return true or false, the errors found etc. Can also clean the input from all non-approved chars.

Written by Jolle Carlestam in an iterative process with Chris Wik, Ke Carlton and Tim Taplin after a discussion on the Lasso 9 beta list 2010-08-12

Usage:
local('test_num' = jina_validatephone('1-970-728-9773'));
#test_num -> valid;
#test_num; // Returns true or false, same as using jina_validatephone -> valid
#test_num -> errors;
#test_num -> findvalue;
#test_num -> inputvalue;
#test_num -> cleanup;

*/
define jina_validatephone => type {
	data private err::array
	data private find = `[^\d \.\+\-()]+` // Kyle revealed that using backticks you can skip doubling up on backslashes
	data private valid = false
	data private input::string

	public oncreate(
		input::string,
		find::string = .'find'
		) => {
		.'input' = #input -> ascopy;
		.'find' = #find -> ascopy;

		local(reg_exp = regexp(-find = .'find', -input = .'input', -ignorecase));

		.'err' = #reg_exp -> findall;

		.'err' -> size == 0 ? .'valid' = true;

	}

	public oncreate(
		-input::string,
		-find::string = .'find'
		) => .oncreate(#input, #find)

	public asString() => .'valid'
	public valid() => .'valid'
	public errors() => .'err'
	public findvalue() => .'find'
	public inputvalue() => .'input'

	public cleanup() => {
		return regexp(-find = .'find', -input = .'input', -replace = '', -ignorecase) -> replaceall;
	}

}

?>

 

Related Tags



Comments

none

Email:


Password:



Newest

Most Popular

Support tagSwap.net