PHPandME1 Posted May 18, 2013 Share Posted May 18, 2013 I am very much a php beginner and I am trying to figure out how to write some to code to validate a social security number. The question I am working on is: "Write a PHP function called isValidSSN that validates a social security number. The function takes 2 parameters. The first parameter is a string that represents the ssn. The second parameter is a reference parameter that will store the error message generated by the function when the ssn is incorrect. The error message should indicate if a ssn was not provided or if the ssn that was provided is in the wrong format. A valid ssn must be in the format ###-##-#### where # is a digit and the dashes MUST be included. The function should return true if the ssn is valid and false if the ssn is invalid." I am completely lost so any assistance would be much appreciated. Thank you! Link to comment https://forums.phpfreaks.com/topic/278144-help-with-ssn-validation/ Share on other sites More sharing options...
kicken Posted May 19, 2013 Share Posted May 19, 2013 There are various ways to accomplish the validation. You can use trim and a comparison to the empty string to check if it was not provided. You could learn some basic regular expressions and use preg_match to match the required format. Another way to match the format would be a combination of explode, ctype_digit and strlen. Link to comment https://forums.phpfreaks.com/topic/278144-help-with-ssn-validation/#findComment-1430898 Share on other sites More sharing options...
PHPandME1 Posted May 19, 2013 Author Share Posted May 19, 2013 I would like to accomplish this task using the preg_match reg expression. What would that look like? Link to comment https://forums.phpfreaks.com/topic/278144-help-with-ssn-validation/#findComment-1430908 Share on other sites More sharing options...
Psycho Posted May 19, 2013 Share Posted May 19, 2013 This is obviously a homework assignment. At least make an attempt and post what you try. Link to comment https://forums.phpfreaks.com/topic/278144-help-with-ssn-validation/#findComment-1430918 Share on other sites More sharing options...
darkfreaks Posted May 19, 2013 Share Posted May 19, 2013 http://snipplr.com/view/14152/ at least google some options before asking for help. Link to comment https://forums.phpfreaks.com/topic/278144-help-with-ssn-validation/#findComment-1430929 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.