Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

InStr Function 1

Status
Not open for further replies.

riarc

Programmer
Dec 6, 2001
44
US
How do use the InStr function to validate a Social Security number? XXX-XX-XXXX Should I look for the dashes?
 
Hi,

First of all you should make it clear to yourself what you mean by validate the number. What criterias should be met in order for the number to be valid? (the Danish social secruity numbers must meet a special matematical formula in order to be valid).
This might also help (assume that s contains the social security number):

if isnumeric(left$(s,3)) and mid$(s,4,1)="-" and isnumeric(mid$(s,5,2)) and mid$(s,7,1)="-" and isnumeric(mid$(s,8)) and len (s)=11 then ...
Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Thanks..that worked just as I wanted it to.
 
Hi All,

Code doesn't work in all cases, try typing:-

IsNumeric(Left$("1E1", 3))
IsNumeric(Left$("12.", 3))
IsNumeric(Left$("12,", 3))

All return True


Codefish
 
Which is, I suppose, because numbers can have commas in them. But not normally at the end. Peter Meachem
peter@accuflight.com
 

Hi,

If you want to avoid the problem that codefish mentions, you can write your own isnumeric function. Something like (I don't have my VB here, so excuse any errors):

private sub IsNum(TheString as string) as boolean
dim i as long, MyCharAsc as string*1

for i = 1 to len(TheString)
MyCharAsc = asc(mid$(TheString,i,1))
if MyChar<48 or MyChar>58 then IsNum=false:exit function
next i
isnum=true
end sub

Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top