I am doing Postal code validation. The postal code can take 7 Alphanumerics inclucluding one blank. Now when I enter the postal code without any space(A1ED3R) or it will create an empty space in the middle(A1E D3R) which is correct. But if I put a space anywhere else like(A 1ED3R) it is showing me exactly like this(A 1ED3R) after validation. I want to put only one space in the middle like(A1E D3R) no matter where I put the space.
I am using substring for the validation here. I would appreciate if someone can help me. Thanks!!!
Are you aware of regular expressions. They let you express patterns in a very compact way. So you could say you want one "whitespace or alphanumeric character" followed by 5 alphanumeric followed by one whitespace/alphanumeric. Or similar. Which isn't your pattern of course.
Of you could get rid of the blank and add it in at the end.
I changed the condition to if (postalCode.length == 6)
Now I am still getting wherever I put the space and another space in the middle and the last letter is getting disappeared. So if the enter (A 1ED3R) the result I am getting is (A 1E D3). Here is the changed code.