The number I'm looking for is valid when it's positive, and nine digits. I used ( (value >= 100000000) && (value <= 999999999) ) first, which worked okay, but did not account for leading zeroes. How do I validate a nine digit number, using only math and no functions, with possible leading zeroes?
idlackage 0 Light Poster
Recommended Answers
Jump to PostStart with strlen(), before you convert it.
Jump to PostThe number I'm looking for is valid when it's positive, and nine digits. I used ( (value >= 100000000) && (value <= 999999999) ) first, which worked okay, but did not account for leading zeroes. How do I validate a nine digit number, using only math and no functions, with …
Jump to PostConverting a string to an int (without functions) is no harder than working out the length of the string (without functions).
In fact, you can pretty much cover it with the same code.
All 12 Replies
Adak 419 Nearly a Posting Virtuoso
Salem 5,265 Posting Sage
Adak 419 Nearly a Posting Virtuoso
jephthah 1,888 Posting Maven
Salem 5,265 Posting Sage
jephthah 1,888 Posting Maven
idlackage 0 Light Poster
jephthah 1,888 Posting Maven
idlackage 0 Light Poster
jephthah 1,888 Posting Maven
idlackage 0 Light Poster
jephthah 1,888 Posting Maven
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.