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! Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.