how to check there exist number in string using isalpha.if number exist, display "only alphabetic,please input again"

example :
user input = i had to 2 number

Recommended Answers

All 5 Replies

Is it really that hard?


I don't know if that takes a string or not, but if it's only a character then just loop through.

If isalpha() failes it does not mean that the character is a numeric digit, it could be anything else too. If you want to check for numeric digits then use isdigit(). And both only check one character, so if you have a whole string then you must check each character individually.

If you want to make sure there are no numbers in a string, you can do a find_first_of( "01234567890"). If it equals anything other than string::npos, it's got a number in there.

what if we dont have to use library functions.

commented: Don't bump old threads -1

Well, in that case just do it the hard way -- put this in a loop if( string[i] >= '0' || string[i] <= '9' )

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.