Poor checkout validation

Please post your issues and questions about One Page Checkout for Virtuemart 2 to this forum.

Poor checkout validation

Postby info@.....cz » Wed Jul 02, 2014 9:24 am

Hi Stan,
I've found out that in our OnePage checkout form, the validation is not strong enough. Validation checks if the required fields are filled correctly, then it checks email format and that's all it checks.
Image

In this case, all fields with asterisk are checked whether they're filled or not. That's okay.
Then, there is a need for some format validation - email should be either xxx@yyy.zz, xxx@yyy.zzz or xxx@yyy.zzzz (in case of .info domain), phone number should contain numbers only and the same goes for post code.
Instead, email validation checks only whether the email consists of two words separated by at sign ("@"). For example, "test" won't pass the validation, but "test@test" without any domain is accepted by OPC, which is not enough.
Phone number format and post code format are not validated at all.

Did I do something wrong, am I missing some configuration? If not, are you planning to add better validation soon? If not, where can I do it myself without a component core hack?

I've searched through other topics and found that it's all up to tabcontent.js in my template folder (threecolumn_special_blue), which is referencing onepage.js - that's where is the RegExp to check the email format. However, I'm not really up for any OPC core JS hacking, not even a js file.
The RegExp that you could use would be just as simple as this (or anything else you like but also requiring .domain at the end of the email address)
Code: Select all
new RegExp("^[^.]+(\.[^.]+)*@([^.]+[.])+[a-zA-Z]{2,4}$");


Thank you for any information about this!

Using Joomla 2.5.22, VM 2.6.6 and OPC 2.0.250.240614

Kind regards,
Tom
info@.....cz
 
Posts: 21
Joined: Thu Sep 26, 2013 11:08 pm

Re: Poor checkout validation

Postby admin » Wed Jul 02, 2014 12:54 pm

hello tom, the email can also consist of utf8 characters so they can be compatible with chinese or russian systems, the email validation is very complicated and due to the compatibility we only included the standard set:
email validation regex (does not support utf8 chars):
var pattern = "[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])";

we are not that expers in the regex field and if you have any suggestions, it would be welcome.

username validation regex (disallowed characters):
var pattern = "^[^#%&*:<>?/{|}\"';()]+$";


phone numbers are better not validated towards a number because they usually have different syntax in each country. they may start with zero, double zeros, plus and contain symbols like - or use a suffix which is not a part of the phone number itself. therefore most systems do not validate the phone number toward the syntax.

the zip is the same case - some countries like UK are using non-numeric zip codes, some countries like ireland are using no zip codes and countries like US are using mostly numeric zipcodes which even may be the same for two different areas and in some special cases (new york) also a suffix is sometimes used to express a specific location (building) within the area.

what i could do from opc point is that i may add html5 options into opc display tab, so if you require a numeric zip, it would be marked as numeric and modern browsers would not allow any non-numeric characters.

best regards, stan
admin
Site Admin
 
Posts: 2708
Joined: Wed Jan 06, 2010 11:43 pm

Re: Poor checkout validation

Postby info@.....cz » Wed Jul 02, 2014 9:43 pm

Thank you for your reply and extensive explanation. Now I completely understand and I don't mind the phone number and zip validation not being validated in OPC when it has reasons.

I'm not a regular expressions expert either, but I think that it's not that difficult to tweak it to also require ".domain" at the end. If you write email@address into the email field, it passes the validation and that's a pity. I believe you could improve the RegExp you already have to reach this functionality. In my honest opinion, it would make OPC validation way better and everyone from any country would benefit from it.

Now when I understand why OPC doesn't include validation for every field, could you please briefly explain where exactly can I write my own validation? I suppose it should be somewhere in tabcontent.js, but I'm not sure how exactly should I write it. I know how to write a body of the needed function, I only don't know all the stuff around to make sure it will apply after pushing the Confirm order bottn. If it If I write a simple function, it won't call itself on its own, that's what I need to clear.

Thanks,
Tom
info@.....cz
 
Posts: 21
Joined: Thu Sep 26, 2013 11:08 pm

Re: Poor checkout validation

Postby admin » Mon Jul 07, 2014 5:53 pm

hello tom, please see this post on how to add your custom validation:
https://www.rupostel.com/phpBB3/viewtopic.php?f=5&t=913

you can include the script from your include.php or from opc theme files. it's handled by onepage.js
the tabcontent.js are only theme specific javascript helper functions.

the vm1 was btw originately made for intranet which does not use the full domain name, but yes, we will surely add it there.

best regards, stan
admin
Site Admin
 
Posts: 2708
Joined: Wed Jan 06, 2010 11:43 pm

Re: Poor checkout validation

Postby info@.....cz » Tue Jul 08, 2014 9:27 am

Thank you, Stan.

For better email regex, please, check out this StackOverflow post or go for your custom solution by following this great article.
info@.....cz
 
Posts: 21
Joined: Thu Sep 26, 2013 11:08 pm


Return to One Page Checkout for Virtuemart 2