Check input character is alphabet, digit or special character

19 Apr, 2021
All characters whether alphabet, digit or special character have ASCII value. Input character from the user will determine if it’s Alphabet, Number or Special character.ASCII value ranges-  
For capital alphabets 65 – 90
For small alphabets 97 – 122
For digits 48 – 57
Examples :  
Input : 8
Output : Digit

Input : E
Output : Alphabet
 
 
C++
Java
Python3
C#
PHP
Javascript
// CPP program to find type of input character#include <iostream>using namespace std; void charCheck(char input_char){    // CHECKING FOR ALPHABET    if ((input_char >= 65 && input_char <= 90)        || (input_char >= 97 && input_char <= 122))        cout << " Alphabet ";     // CHECKING FOR DIGITS    else if (input_char >= 48 && input_char <= 57)        cout << " Digit ";     // OTHERWISE SPECIAL CHARACTER    else        cout << " Special Character ";} // Driver Codeint main(){    char input_char = '$';    charCheck(input_char);    return 0;}
// Java program to find type of input characterimport java.io.*; class GFG {     static void charCheck(char input_char)    {        // CHECKING FOR ALPHABET        if ((input_char >= 65 && input_char <= 90)            || (input_char >= 97 && input_char <= 122))            System.out.println(" Alphabet ");         // CHECKING FOR DIGITS        else if (input_char >= 48 && input_char <= 57)            System.out.println(" Digit ");         // OTHERWISE SPECIAL CHARACTER        else            System.out.println(" Special Character ");    }     // Driver Code    public static void main(String[] args)    {        char input_char = '$';        charCheck(input_char);    }} // This code is contributed by vt_m.
# python program to find type of# input character def charCheck(input_char):         # CHECKING FOR ALPHABET    if ((int(ord(input_char)) >= 65 and        int(ord(input_char)) <= 90) or        (int(ord(input_char)) >= 97 and        int(ord(input_char)) <= 122)):        print( " Alphabet ")         # CHECKING FOR DIGITS    elif (int(ord(input_char)) >= 48 and            int(ord(input_char)) <= 57):        print(" Digit ")     # OTHERWISE SPECIAL CHARACTER    else:        print(" Special Character ") # Driver Codeinput_char = '$'charCheck(input_char) # This code is contributed by Sam007.
// C# program to find type of// input characterusing System; class GFG {     // Function to check type    // of input character    static void charCheck(char input_char)    {        // Checking for Alphabet        if ((input_char >= 65 && input_char <= 90)            || (input_char >= 97 && input_char <= 122))            Console.WriteLine(" Alphabet ");         // Checking for Digits        else if (input_char >= 48 && input_char <= 57)            Console.WriteLine(" Digit ");         // Otherwise Special Character        else            Console.WriteLine("Special Character");    }     // Driver Code    public static void Main()    {        char input_char = '$';        charCheck(input_char);    }} // This code is contributed by vt_m.
<?php// PHP program to find type// of input character function charCheck($input_char){    // CHECKING FOR ALPHABET    if (($input_char >= 65 && $input_char <= 90)        || ($input_char >= 97 && $input_char <= 122))        echo " Alphabet ";         // CHECKING FOR DIGITS    else if ($input_char >= 48 &&            $input_char <= 57)    echo " Digit ";     // OTHERWISE SPECIAL CHARACTER    else                                       echo " Special Character ";} // Driver Code$input_char = '$';charCheck($input_char); // This code is contributed by Sam007?>
<script>      // JavaScript program to find type of input character      function charCheck(input)      {        var input_char = input.charCodeAt(0);                 // CHECKING FOR ALPHABET        if (          (input_char >= 65 && input_char <= 90) ||          (input_char >= 97 && input_char <= 122)        )          document.write(" Alphabet ");                   // CHECKING FOR DIGITS        else if (input_char >= 48 && input_char <= 57)          document.write(" Digit ");                   // OTHERWISE SPECIAL CHARACTER        else document.write(" Special Character ");      }       // Driver Code      var input_char = "$";      charCheck(input_char);             // This code is contributed by rdtank.    </script>
Output :  
 Special Character 
 
vt_m
Sam007
SopanShrivastava
Pawansinghkushwah
rdtank
C++
School Programming
CPP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Bitwise Operators in C/C++
Templates in C++ with Examples
Operator Overloading in C++
Inheritance in C++
Queue in C++ Standard Template Library (STL)
Python Dictionary
Reverse a string in Java
Interfaces in Java
Inheritance in C++
Operator Overloading in C++