CFLib.org – Common Function Library Project

IsSSN(str)

Last updated April 27, 2005

author

Jeff Guillaume

Version: 2 | Requires: CF5 | Library: StrLib

Description:
Checks passed value to see if it is a properly formatted U.S. social security number. Returns True or False.

Return Values:
Returns a Boolean.

Example:

<cfoutput>
379-80-0001: #YesNoFormat(IsSSN("379-80-0001"))#<br>
572394546: #YesNoFormat(IsSSN("572394546"))#<br>
237-33-0000: #YesNoFormat(IsSSN("237-33-0000"))#<br>
000-33-5786: #YesNoFormat(IsSSN("000-33-5786"))#<br>
</cfoutput>

Parameters:

Name Description Required
str String you want to validate. Yes

Full UDF Source:

/**
 * Checks passed value to see if it is a properly formatted U.S. social security number.
 * Cameron Childress found a bug in the right(str,4) line.
 * 
 * @param str 	 String you want to validate. (Required)
 * @return Returns a Boolean. 
 * @author Jeff Guillaume (jeff@kazoomis.com) 
 * @version 2, April 27, 2005 
 */
function IsSSN(str) {
  // these may actually be valid, but for business purposes they are not allowed
  var InvalidList = "111111111,222222222,333333333,444444444,555555555,666666666,777777777,888888888,999999999,123456789";
	
  // validation based on info from: http://www.ssa.gov/employer/ssnweb.htm
  if (REFind('^([0-9]{3}(-?)[0-9]{2}(-?)[0-9]{4})$', str)) {
    if (Val(Left(str, 3)) EQ 0) return FALSE;
    if (Val(Right(str, 4)) EQ 0) return FALSE;
    if (ListFind(InvalidList, REReplace(str, "[ -]", "", "ALL"))) return FALSE;
    // still here, so SSN is valid
    return True;
  }
  // return default
  return False;
	
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson