@antorroydravi your request or complaint, entirely in the title of your post, viz:
My code is not working as intended. actually it just check only 12 character and show me valid or invalid. but i want it to check the whole id first then show me either its valid or not. can anyone help me with this? It will be very helpful
Doesn't carefully explain how you want it to function. Please take a minute and tell us how you want it to work from the perspective of someone using your system.
The code does recognize valid and invalid 12 character IDs, but does so in a…, well let's just say not how I would do it, and not how it might better be done.
As for the moot-ness of what is attached to the "serial line", I assume @ AWOL means "subject to debate, dispute, or uncertainty", and not "having little or no practical relevance" as it could also be interpreted.
We would have been well served with just a few more of the precious life-time supply of words we are all granted on why it matters, perhaps sparing us some of this "debate".
The OP's code depends on the the ability of whatever is attached to the "serial line" to deliver 12 characters with no gaps greater than 500 milliseconds between them.
This is trivially accomplished with the serial monitor's input window, and perhaps by almost any external serial device or emulator. But there would be a surprising change in success if, for example, the characters arrived at the rate a human keyed them, as can be configured in some terminal programs or, perhaps, a keypad with a serial intercase.
The OP's code also quietly (and probably on accident of the coder) eats characters like CR and LF and shorter attempts and probably a few other things - only from an equilibrium state (serial buffer emtpy and count reset achieved after the gap in arrival of characters) is the program ready to take in the 12 char ID. This, too, may finally come to be an issue when the system is deployed with the eventual input device, serial or as it may even switched away from from a simulated by serial to a keypad getchars or whatever.
So that's an expenditure of 1 x 10e-5 percent of my lifetime supply of words, I certainly hope that helps y'all.