C++ Program to check string is alphanumeric or not


In this program, You will learn how to check string is alphanumeric or not in C++.


Some list of alphanumeric string: xiith123, john34, amit23, abc_98

alphanumeric string is called with integer value.


Example: How to check string is alphanumeric or not in C++

Run it Now
#include<iostream>
#include<cstring>
using namespace std;

int main() {

    char str[100];

    cout << "Enter a String :";
    cin.getline(str, 100);

    int i = 0, k = 0, dig = 0, p;
    i=strlen(str);

    for (int j = 0; j < i; j++) {

        p = str[j];
        if (p >= 97 && p <= 122)
            k++;
        else if (p >= 65 && p <= 90)
            k++;
        else if (p == 32)
            k++;
        else if (p >= 48 && p <= 57)
            dig++;
    }

    if (k > 0 && dig > 0) {
        cout << "\nString is AlphaNumeric :" << str;
    } else {
        cout << "\nString is Not AlphaNumeric :" << str;
    }

    return 0;
}

Output:

Enter a String :Hello y2
String is AlphaNumeric :Hello y2