Given a string str, the task is to check if the string is a valid identifier or not. In order to qualify as a valid identifier, the string must satisfy the following conditions:
- It must start with either underscore(_) or any of the characters from the ranges [‘a’, ‘z’] and [‘A’, ‘Z’].
- There must not be any white space in the string.
- And, all the subsequent characters after the first character must not consist of any special characters like $, #, % etc.
Input: str= “_geeks123”
Input: str = “123geeks_”
Approach: Traverse the string character by character and check whether all the requirements are met for it to be a valid identifier i.e. first character can only be either ‘_’ or an English alphabet and the rest of the characters must neither be a white space or any special character.
Below is the implementation of the above approach:
- Check if a given string is a valid number (Integer or Floating Point) in Java
- Check if a given string is a valid number (Integer or Floating Point) | SET 1(Basic approach)
- Check if a given string is a valid number (Integer or Floating Point) in Java | SET 2 (Regular Expression approach)
- Check whether Quadrilateral is valid or not if angles are given
- Check whether the triangle is valid or not if angles are given
- Program to check for a Valid IMEI Number
- Program to generate all possible valid IP addresses from given string | Set 2
- Program to generate all possible valid IP addresses from given string
- String slicing in Python to check if a string can become empty by recursive deletion
- Check if a string can be converted to another string by replacing vowels and consonants
- Check if a string can be obtained by rotating another string 2 places
- Check if a string can be obtained by rotating another string d places
- Check if a string can become empty by recursively deleting a given sub-string
- Queries to check if string B exists as substring in string A
- Check whether second string can be formed from characters of first string
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.