![]() |
VOOZH | about |
Let's write a Java Program that checks whether a given variable name complies with the naming convention or not using Regular Expressions in Java.
Input: _myName
Output: CorrectInput: 2ndVariable
Output: Incorrect
Below is the implementation to Check Variable Name is Valid according to the Naming Convention:
myVariable123 is valid: true 3rdVariable is valid: false
The regular phrase ^[a-zA-Z_$] is the main idea.[a-zA-Z_$0–9]*$ guarantees that the variable name is