- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check if a character is alphanumeric in Arduino
Depending on your use case, you may need to check if a character is alphanumeric or not in Arduino. One example can be validating password strings, wherein you’ve allowed only alphanumeric characters for passwords. Or checking file names for storage in SD Card (sometimes some special characters are not allowed in file names). Arduino has an inbuilt function which checks whether a given character is alphanumeric or not. As you would have guessed, the function is isAlphaNumeric() and it takes in a character as the argument, and returns a Boolean.
Example
void setup() { // put your setup code here, to run once: Serial.begin(9600); Serial.println(); char c1 = 'a'; char c2 = '1'; char c3 = '%'; if (isAlphaNumeric(c1)) { Serial.println("c1 is AlphaNumeric!"); } else { Serial.println("c1 is NOT AlphaNumeric!"); } if (isAlphaNumeric(c2)) { Serial.println("c2 is AlphaNumeric!"); } else { Serial.println("c2 is NOT AlphaNumeric!"); } if (isAlphaNumeric(c3)) { Serial.println("c3 is AlphaNumeric!"); } else { Serial.println("c3 is NOT AlphaNumeric!"); } } void loop() { // put your main code here, to run repeatedly: }
Output
The Serial Monitor output is shown below −
As you can see, the function works as expected, and returns true for alphabets and numbers, but not for special characters. You can try this out for other characters.
- Related Articles
- Check if a character is printable in Arduino
- Check if a character is Space/Whitespace in Arduino
- Check if a character is a punctuation mark in Arduino
- How to check if a string is alphanumeric in Python?
- What is the Python regular expression to check if a string is alphanumeric?
- C# Program to check if a character is a whitespace character
- Python - Check If All the Characters in a String Are Alphanumeric?
- Fetch rows where first character is not alphanumeric in MySQL?
- How to check if a character is upper-case in Python?
- Check if the board is connected or not in Arduino IDE
- How to check if a character in a string is a letter in Python?
- How to check if a given character is a number/letter in Java?
- Check whether the Unicode character is a separator character in C#
- Check if two strings are equal or not in Arduino
- Python Program to accept string ending with alphanumeric character
