-1

I have two source files: searchworker and searchvalidator. The worker provide how program will work (logically) and validator is just validate user input.

In my case, the system will run correctly if user input 9 digits of key (e.g. GGHYK1221) with no exception. If user input less or more than 9 digits it will call error message.

Actually, the key is GG-H-YK-1221. So, it doesn't match with the system spec. It should delete first hyphen (-) manually. Now, I want to allow user input max 12 digits and delete hyphen. I've done delete hyphen using regex, but I'm stuck at set input length to 9 for pass the validator. Any idea to solve this or another ways?

I using Java.

Thank you

  • From your statement, it's not clear how the validator is implemented, or what you mean by being "stuck at set input length 9"...does that mean the validation occurs before you have any chance to apply `String.replaceAll()`? – lockcmpxchg8b Nov 23 '17 at 07:48
  • I mean. I don't have any idea again to solve this. validation occurs after String.replaceAll(). Now, validator only allow 9 digits. I've done to allow more than 9 digits and replace hyphen. But, how do I set input length back to default length validation (9). – Ahmad Fajar Nov 23 '17 at 08:02
  • Where is the input length stored? Is it on a GUI component? How do you get the user input presently, so as to modify it? – lockcmpxchg8b Nov 23 '17 at 08:05
  • User input in input box that created in jsp. I call valueX in java to process the input. – Ahmad Fajar Nov 23 '17 at 08:08
  • can you show the code for "calling valueX"? I don't follow the meaning. (You can add that to the question, where you can format it better) – lockcmpxchg8b Nov 23 '17 at 08:34

1 Answers1

0

You can use intermediate temp variable to do the translation and set back to original value if required.

OR you can maintain global varible for this, try either option.

Ramesh Fadatare
  • 561
  • 4
  • 12