Lasso Soft Inc. > Home

[Phone]

LinkPhone
AuthorSeth Ganahl
CategoryString
Version8.x
LicensePublic Domain
Posted03 Apr 2012
Updated03 Apr 2012
More by this author...

Description

Formats 10 digit input as US phone number. Ex: 1234567890 becomes (123) 456-7890. Based on code from Steve Piercy, Bil Corry, and Keith Schuster

Sample Usage

[phone: '1234567890']

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.

define_tag('phone', -description='Formats 10 digit input as US phone number.  Ex: 1234567890 becomes (123) 456-7890.',
  -required='number', -type='string', -copy,    
  // the phone number to test (and optionally format) 		-priority='replace'); 	 	

  #number = string_replaceregexp(#number,-find='\\D',-replace=''); 	
  
  if: #number == null;	
    #number = string;
  /if;

  #number->(removeleading: '0');
  #number->(removeleading: '1`');

  if: #number->size == 10;
    // format the number;
    #number = '(' (#number->(substring:1,3)) ') ' (#number->(substring:4,3)) '-' (#number->(substring:7,4)); 	
  else;
    #number = 'Not a valid Phone Number.';
  /if;

  return(#number);

/define_tag;

Comments

No comments

Please log in to comment

LassoSoft Inc. > Home

 

 

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