![]() |
VOOZH | about |
Given some PF(Provident Fund) Account Number, the task is to check if they are valid or not using regular expressions. Rules for the valid PF Account Number are :
Examples:
Input: str = "TN MAS 1207199 123 1234567"
Output: TrueInput: str = "TN/MAS/1207199/123"
Output: False
Approach: The problem can be solved based on the following idea:
Create a regex pattern to validate the number as written below:
regex = "^[A-Z]{2}[\s\/]?[A-Z]{3}[\s\/]?[0-9]{7}[\s\/]?[0-9]{3}[\s\/]?[0-9]{7}$"Where,
- ^: Start of the string
- [A-Z]{2}: 2 alphabets characters should be there.
- [\s\/] : Either space or forward slace
- [0-9]{3} : 3 digits should be there.
Follow the below steps to implement the idea:
Below is the implementation of the above approach:
true true true false false
Time Complexity: O(N) for each testcase, where N is the length of the given string.
Auxiliary Space: O(1)
Related Articles: