Wrong format on postal code after form submit
I have on my website a simple form where the user enters personal
information to register as a new user.
My problem is that in some cases the postal code allows illegal characters
even though i have a JavaScript validation on the onkeyup event of my
input-tag. This doesn't happen often but still happens.
In Sweden the standard postal code is a 5 digit number and my validation
checks for input of illegal characters and then in my submit validation
checks against the length before allowing submit of the form.
Example code
function check_Postal()
{
document.RegisterForm.Postal.value =
document.RegisterForm.Postal.value.replace(/[\^0-9]/g,"");
if (document.RegisterForm.Postal.value.length ==
$clientProfilField{'PostalnrMax'})
{
document.RegisterForm.Postal.className="ClientprofileFieldOK";
}
}
PostalnrMax is 5 for this example.
The way you normally write a postal code in Sweden is XYZ AB. My problem
is that some of my users postal codes are written to the database as XYZ
A. In the three last occurrences, the users have been using Chrome. I've
tried to recreate the problem but have been unsuccessful. I'm assuming
that the problem is that the users somehow enter their postal code as you
normally would (XYZ AB) and my validation against length cuts off the last
character.
So my question is, how are the users able to enter a faulty postal code?
When i try it, it replaces space immediately with "". Has it something to
do with Chrome autofill?
Any inputs are greatly appreciated!
Thanks in advance, David
No comments:
Post a Comment