1.11M Members

Formatting social security number

 
0
 

I have Googled and looked and looked. What is the best cleanest way to format a social security number to look like xxx-xx-xxxx?

And as long as I am asking, how about how to ensure that a nine digit number is entered?

Thank you!

 
0
 

Which control are you using to take SSN from user?

 
0
 

And SSN format differs from place to place which country's SSN You are talking about?

 
0
 

Hello AbelLazm, Its just me again with the taxpayer code I am working on. US SSN so dashes after 3rd and 5th number in series. Has to be entered as a string.

//  Implement a for-loop that will prompt the user to enter the Social Security Number and gross income.
                for (x = 1; x < taxArray.Length; ++x)
                {
                    taxArray[x] = new Taxpayer();
                    Console.Write("Please enter the Social Security Number for taxpayer {0}, (format as xxx-xx-xxx):  ", x);
                    taxArray[x].SSN = Console.ReadLine();
 
1
 

try this code

String s="";
            bool flag = true;
            while (flag)
            {
                Console.WriteLine("Enter the string");
                s = Console.ReadLine();
                if (s.Length != 9)
                    Console.WriteLine("Wrong Input String must have 9 charachters Enter again");
                else flag = false;

            }
            //Format according to xxx-xx-xxxx
            s = String.Format("{0}-{1}-{2}", s.Substring(0, 3), s.Substring(3, 2), s.Substring(5, 4));
            Console.WriteLine(s);
            Console.ReadLine();
 
0
 

AWESOME. Thank you. :oD

Question Answered as of 3 Years Ago by abelLazm
 
0
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            textBox1.MaxLength = 11;
            textBox1.TextAlign = HorizontalAlignment.Center;
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            {
                if (textBox1.Text.Length == 3)
                {
                    textBox1.Text += '-';
                    textBox1.SelectionStart = 5;
                }
                if (textBox1.Text.Length == 6)
                {
                    textBox1.Text += '-';
                    textBox1.SelectionStart = 8;
                }

            }
        }
    }
}
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article