Hi,

i am trying to write an application that uses validation check for social security number. it should allow 9 charachters. the first two and the last character should be leters and the rest should be digits.

i have used for loop but it doesnt work properly.

int noChar = 0;
for (i=0;i<8;i++)
{
char ch=aString.charAt(i)
if (noChar.isLetter(ch)==0||noChar.isLetter(ch)==1||noChar.isLetter(ch)==8){
return true;
}
else return false;
}
}

I'd have a look at regular expressions. Specifically, you want the matches(String regex) method of java.lang.String.

Tell me What exactly you rae trying to do.

Are you trying to mAtch the value from Database

Or you are matching the SSN with a dummy value taken in the Program itself

Can you provide more information or source code

He said exactly what he is trying to do.
He is trying to check that the input string starts with 2 letters, then has 6 digits, then another letter.

Which no doubt isn't enough and might not even be accurate...

At most it tells you whether the string could represent a US SSN, not whether it actually does.
And if there are more restrictions on how an SSN is constructed it may not do even that.

it should allow 9 charachters. the first two and the last character should be leters and the rest should be digits.

At most it tells you whether the string could represent a US SSN

Which is exactly what he asked for. If he wants it to actually check if the string is an American Social Security number, that would require a lot more work.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.