157. Check if String Contains Only Digits

EasyStringString

Given a string s, return 'true' if the string consists entirely of digit characters (0–9), and 'false' otherwise.

An empty string should return 'false'.
Spaces, signs (+/-), and decimal points are not considered digit characters.

Input: A single string s.

Output: Return 'true' if all characters are digits (0-9), otherwise 'false'.

Examples

Example 1
Input: 12345
Output: true
Explanation: All five characters are digits → true.
Example 2
Input: 123abc
Output: false
Explanation: Contains letters 'a', 'b', 'c' → false.
Example 3
Input: 3.14
Output: false
Explanation: The decimal point '.' is not a digit → false.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →