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:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Check whether the triangle is valid or not if angles are given
- Check whether Quadrilateral is valid or not if angles are given
- Difference between Keyword and Identifier
- Python | Check if a given string is binary string or not
- Check if given string is a substring of string formed by repeated concatenation of z to a
- C Program to Check Whether a Number is Prime or not
- Check whether the number can be made perfect square after adding 1
- Check if the given string is linear or not
- Check if the string contains consecutive letters and each letter occurs exactly once
- Check if two same sub-sequences exist in a string or not
- Program to check similarity of given two triangles
- Check if it is possible to create a polygon with given n sides
- Check if given two straight lines are identical or not
- Reverse words in a given string
- Find the character made by adding all the characters of the given string
- Minimum cost to convert given string to consist of only vowels
- PHP | check if a number is Even or Odd
- PHP | Check if a number is prime
- PHP | Check if a number is Perfect number
- Program to check congruency of two triangles
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.