Skip to content

Instantly share code, notes, and snippets.

View tesshsu's full-sized avatar
🎯
Focusing

tess hsu tesshsu

🎯
Focusing
View GitHub Profile
@tesshsu
tesshsu / with unit testing case with Jquery
Last active January 10, 2018 08:52
VAT regular Expresion
jQuery("form#adminForm, form#userForm").on("submit", function(event) {
var isTva = true;
var inputsTva = jQuery('form#adminForm #pluginistraxx_euvatchecker_field');
// define reg part, each country code has match different quantifier
// for example, GB matches the characters GB literally (case sensitive), matches a digit 0-9, Matches exactly 5 times
var regTva = /^(RO\d{2,10}|GB\d{5}|GBGD\d{3}|CHE\d{9}|CZ\d{8,10}|(ATU|DK|FI|HU|LU|MT|SI)\d{8}|IE[A-Z\d]{8}|(DE|BG|EE|EL|LT|BE0|PT)\d{9}|CY\d{8}[A-Z]|(ES|GB)[A-Z\d]{9}|(BE0|PL|SK|RU)\d{10}|(FR|IT|LV)\d{11}|(LT|SE)\d{12}|(NL|GB)[A-Z\d]{12})$;/g;
//bind each related tva input, if not pass reg, return false
jQuery.each(inputsTva, function(){
if(!regTva.test(jQuery(this).val())) {
isTva = false;
@tesshsu
tesshsu / demo.png
Last active January 20, 2017 01:47
module: add people list
demo.png
@tesshsu
tesshsu / Addmethod.js
Last active January 20, 2017 01:24
validate + Ajax post demo
$.validator.addMethod( "forValidPhone", function( value, element ) {
return this.optional( element ) || /^\((\d{3})\)[- ]?(\d{3})[- ]?(\d{4})$/i.test( value );
}, "please enter the correct phone format" );
$.validator.addMethod( "forValidSsn", function( value, element ) {
return this.optional( element ) || /^(\d{3}-\d{2}-\d{4})$/i.test( value );
}, "please enter the correct ssn format" );
@tesshsu
tesshsu / AmexSupport.js
Created January 10, 2017 00:31
Function which detecting if country support/not support Credit Cart Amex payment, if support show the Amex credit card logo, if not hide.
function isAmexNotSupported(type) {
var selectedCountryCode = $('#selected-country').parents('.dr_inputBox').find('li.active').data('country-code');
var notAllowedCountries = ['AFG', 'ARG', 'BRA', 'COG', 'CIV', 'GNQ','ERI','FLK','GLP','GNB','IND','IRQ','LAO','LBY','MEX','MMR','SHN','STP','TUV' ];
var AmexNotSupportedCountries = notAllowedCountries.concat(AmexNotSupportedCountries);
if(AmexNotSupportedCountries) {
@tesshsu
tesshsu / customise_email.js
Created January 10, 2017 00:30
Customise email validation specially for Polish and Arabic Characters
$.validator.addMethod('supportSpecialCharEmail', function(value) {
var specialCharacter = 'ÀÈÌÒÙàèìòùÁÉÍÓÚÝáéíóúýÂÊÎÔÛâêîôûÃÑÕãñõÄËÏÖÜäëïöüąçÇßØÖÜåÆæÞþÐð¡а-яА-ЯёЁ©°\u0100-\u024F\u2E80-\u9FFF\u1100-\u11FF\uAC00-\uD7AF\u0590-\u05FF\u0600-\u06FF\u0750-\u077F\uFB50-\uFC3F\uFE70-\uFEFC\u0600-\u06FF\u0750-\u077F\uFB50-\uFC3F\uFE70-\uFEFC';
var specialSymbol = "!?#\$%\^\&*\)\(+=_.-";
var localPattern = "[a-zA-Z0-9" + specialCharacter + specialSymbol +"]+";
var domainPattern = '[a-zA-Z0-9' + specialCharacter + '](?:[a-zA-Z0-9-' + specialCharacter +']{0,61}[a-zA-Z0-9])?';
var extensionPattern = '[A-Za-z]{2,10}';
var pattern = new RegExp( '^' + localPattern + '@' + domainPattern + '[.]' + extensionPattern + '$');
if (pattern.test($.trim(value))) {
return true;
@tesshsu
tesshsu / Gruntfile.js
Created January 10, 2017 00:24
Billing Form using Unit test for testing user input if correspond to MTX validation rules,also applicable with grunt automation with grunt watch
module.exports = function(grunt) {
var gruntConfig,
taskConfigs;
// set up a configuration
gruntConfig = {
qunit : {
files: 'local-testing/tests/*.html'
}
};
};
@tesshsu
tesshsu / 1.PNG
Last active January 10, 2017 00:22
loading animate spinner write with scss
1.PNG
@tesshsu
tesshsu / index.html
Last active November 22, 2021 01:47
Demo Usage of Angularjs for increase Qty and Price will binding in the same time
<!DOCTYPE html>
<html ng-app>
<head>
<script src="http://code.jquery.com/jquery.min.js"></script>
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet" type="text/css" />
<script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
<meta charset="utf-8">
<title>Tess</title>