Link | jina_validatephone |
Author | Jolle Carlestam |
Category | Utility |
Version | 9.x |
License | Public Domain |
Posted | 12 Aug 2010 |
Updated | 12 Aug 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
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;
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.
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; } } ?>
No comments
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft