[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [bodega-webapp-client/emberjs] public: We don't need a component for the paymentMethod support.
From: Antonis Tsiapaliokas <kok3rs () gmail ! com>
Date: 2014-01-02 16:59:21
Message-ID: E1Vylc9-0001c4-0G () scm ! kde ! org
[Download RAW message or body]
Git commit c388d6677022b0562e8d690c02105437a07551a4 by Antonis Tsiapaliokas.
Committed on 02/01/2014 at 16:46.
Pushed by tsiapaliokas into branch 'emberjs'.
We don't need a component for the paymentMethod support.
We are replacing the existing functionality with a controller.
Also we use the node-validator module in order to
check if the credit card information are valid.
M +94 -0 public/assets/controllers/participant.js
M +0 -78 public/assets/participant.js
M +98 -104 public/assets/templates/participantpaymentmethod.hbs
A +23 -0 public/js/validator-min.js
http://commits.kde.org/bodega-webapp-client/c388d6677022b0562e8d690c02105437a07551a4
diff --git a/public/assets/controllers/participant.js b/public/assets/controllers/participant.js
index 6e9d52c..a63f7b8 100755
--- a/public/assets/controllers/participant.js
+++ b/public/assets/controllers/participant.js
@@ -97,3 +97,97 @@ App.ParticipantPointsController = Ember.ObjectController.extend({
}
}
});
+
+App.ParticipantPaymentMethodController = Ember.ObjectController.extend({
+ cardExpMonthChoice: null,
+ cardExpYearChoice: null,
+ cardTypeChoice: null,
+ cardNameInvalid: false,
+ cardNumberInvalid: false,
+ cardCvcInvalid: false,
+ updatePaymentMethodRequested: false,
+
+ cardExpMonthChoices: function() {
+ var _this = this;
+ var choice = Ember.A();
+ $.map($(Array(12)),function(val, i) {
+ choice.pushObject(i+1);
+ })
+ return choice;
+ }.property(),
+
+ cardExpYearChoices: function() {
+ var _this = this;
+ var choice = Ember.A();
+ var date = new Date();
+ var currentYear = date.getFullYear();
+ $.map($(Array(30)),function(val, i) {
+ choice.pushObject(i+currentYear);
+ })
+
+ return choice;
+ }.property(),
+
+ purchaseMethodMissing: function() {
+ var _this = this;
+ var error = _this.get('error');
+ if (error && error.type) {
+ return error.type === 'PurchaseMethodMissing';
+ }
+ }.property(),
+
+
+ retrieveCardData: function() {
+ var _this = this;
+ var cardData = {
+ 'card': _this.get('cardTypeChoice'),
+ 'inputName': _this.get('cardName'),
+ 'inputNumber': _this.get('cardNumber'),
+ 'inputCvc': _this.get('cardCvc'),
+ 'inputMonthExpires': _this.get('cardExpMonthChoice'),
+ 'inputYearExpires': _this.get('cardExpYearChoice')
+ };
+
+ return cardData;
+ },
+
+ cardDataIsValid: function(cardData) {
+ try {
+ check(cardData['inputName']).isAlpha();
+ this.set('cardNameInvalid', false);
+ } catch (e) {
+ this.set('cardNameInvalid', true)
+ }
+
+ try {
+ check(cardData['inputNumber']).isInt();
+ this.set('cardNumberInvalid', false);
+ } catch (e) {
+ this.set('cardNumberInvalid', true)
+ }
+
+ try {
+ check(cardData['inputCvc']).isInt();
+ this.set('cardCvcInvalid', false);
+ } catch (e) {
+ this.set('cardCvcInvalid', true)
+ }
+
+ },
+
+ actions: {
+ updatePaymentMethod: function() {
+ var _this = this;
+ var cardData = _this.retrieveCardData();
+ _this.cardDataIsValid(cardData);
+ console.log(cardData)
+ _this.set('updatePaymentMethodRequested', true);
+ App.ParticipantPaymentMethod.updatePaymentMethod(cardData).then(function(response) {
+ if (response.error && response.error.type) {
+ _this.set('updatePaymentMethodError', response.error.type);
+ }
+ });
+ }
+ }
+});
+
diff --git a/public/assets/participant.js b/public/assets/participant.js
index ad012e8..9798c2d 100755
--- a/public/assets/participant.js
+++ b/public/assets/participant.js
@@ -131,84 +131,6 @@ App.ParticipantPaymentMethod.reopenClass({
}
});
-App.CreditCardComponent = Ember.Component.extend({
- classNames: ['form-horizontal'],
- tagName: 'form',
- cardExpMonthChoice: null,
- cardExpYearChoice: null,
- cardTypeChoice: null,
- cardNameInvalid: false,
- cardNumberInvalid: false,
- cardCvcInvalid: false,
- updatePaymentMethodRequested: false,
-
- cardExpMonthChoices: function() {
- var _this = this;
- var choice = Ember.A();
- $.map($(Array(12)),function(val, i) {
- choice.pushObject(i+1);
- })
-
- return choice;
- }.property(),
-
- cardExpYearChoices: function() {
- var _this = this;
- var choice = Ember.A();
- var date = new Date();
- var currentYear = date.getFullYear();
- $.map($(Array(30)),function(val, i) {
- choice.pushObject(i+currentYear);
- })
-
- return choice;
- }.property(),
-
- purchaseMethodMissing: function() {
- var _this = this;
- var error = _this.get('error');
- if (error && error.type) {
- console.log(error)
- return error.type === 'PurchaseMethodMissing';
- }
- }.property(),
-
- retrieveCardData: function() {
- var _this = this;
- var cardData = {
- 'card': _this.get('cardTypeChoice'),
- 'inputName': _this.get('cardName'),
- 'inputNumber': _this.get('cardNumber'),
- 'inputCvc': _this.get('cardCvc'),
- 'inputMonthExpires': _this.get('cardExpMonthChoice'),
- 'inputYearExpires': _this.get('cardExpYearChoice')
- };
-
- return cardData;
- },
-
- cardDataIsValid: function(cardData) {
- var _this = this;
- _this.set('cardNameInvalid', !/^[a-z]|[A-Z]+/i.test(cardData['card[name]']));
- _this.set('cardNumberInvalid', !/^[0-9]+$/i.test(cardData['card[number]']));
- _this.set('cardCvcInvalid', !/^[0-9]+$/i.test(cardData['card[cvc]']));
- },
-
- actions: {
- updatePaymentMethod: function() {
- var _this = this;
- var cardData = _this.retrieveCardData();
- _this.cardDataIsValid(cardData);
- _this.set('updatePaymentMethodRequested', true);
- App.ParticipantPaymentMethod.updatePaymentMethod(cardData).then(function(response) {
- if (response.error && response.error.type) {
- _this.set('updatePaymentMethodError', response.error.type);
- }
- });
- }
- }
-});
-
App.ParticipantHistory = Ember.Object.extend({
localeDate: function() {
var date = new Date(this.get('date'));
diff --git a/public/assets/templates/participantpaymentmethod.hbs \
b/public/assets/templates/participantpaymentmethod.hbs index 28ed179..96d2e2b 100644
--- a/public/assets/templates/participantpaymentmethod.hbs
+++ b/public/assets/templates/participantpaymentmethod.hbs
@@ -1,128 +1,122 @@
-<script type="text/x-handlebars" data-template-name="participantPaymentMethod">
- {{#if model.error}}
- {{credit-card error=model.error}}
- {{else}}
- {{credit-card cardData=model}}
- {{/if}}
-</script>
-
+<script src="/js/validator-min.js"></script>
-<script type="text/x-handlebars" data-template-name="components/credit-card">
-
- <fieldset>
+<script type="text/x-handlebars" data-template-name="participantPaymentMethod">
+ <form class="form-horizontal">
+ <fieldset>
- <!-- Update information progress -->
- {{#if updatePaymentMethodRequested}}
- {{#if updatePaymentMethodError}}
- <div class="alert alert-error">
- <button type="button" class="close" data-dismiss="alert">×</button>
- <h3>An error has occur {{updatePaymentMethodError}}</h3>
- </div>
- {{else}}
- <div class="alert alert-success">
- <button type="button" class="close" data-dismiss="alert">×</button>
- <h3>Your credit card information has been updated successfully</h3>
- </div>
+ <!-- Update information progress -->
+ {{#if updatePaymentMethodRequested}}
+ {{#if updatePaymentMethodError}}
+ <div class="alert alert-error">
+ <button type="button" class="close" data-dismiss="alert">×</button>
+ <h3>An error has occur {{updatePaymentMethodError}}</h3>
+ </div>
+ {{else}}
+ <div class="alert alert-success">
+ <button type="button" class="close" data-dismiss="alert">×</button>
+ <h3>Your credit card information has been updated successfully</h3>
+ </div>
+ {{/if}}
{{/if}}
- {{/if}}
-
- <!-- Multiple Radios -->
- <div class="control-group">
- <label class="control-label" for="cardType">Card Type</label>
- <div class="controls">
- <label class="radio" for="cardType-0">
- {{view Ember.RadioButton name="cardTypeSelection" selectionBinding="cardTypeChoice" \
value="Visa"}}
- Visa
- </label>
- <label class="radio" for="cardType-1">
- {{view Ember.RadioButton name="cardTypeSelection" selectionBinding="cardTypeChoice" \
value="Master Card"}}
- Master Card
- </label>
- <label class="radio" for="cardType-2">
- {{view Ember.RadioButton name="cardTypeSelection" selectionBinding="cardTypeChoice" \
value="American Express"}}
- American Express
- </label>
- <label class="radio" for="cardType-3">
- {{view Ember.RadioButton name="cardTypeSelection" selectionBinding="cardTypeChoice" \
value="Dinners Club"}}
- Dinners Club
- </label>
- </div>
- </div>
- <!-- Text input-->
- <div class="control-group">
- <label class="control-label" for="cardName">Name on Card:</label>
- <div class="controls">
- {{input id="cardName" name="cardName" type="text" placeholder="Please type your full name" \
class="input-xlarge" value=cardName}}
- {{#if cardNameInvalid}}
- <p class="text-error">Your name is not valid</p>
- {{/if}}
+ <!-- Multiple Radios -->
+ <div class="control-group">
+ <label class="control-label" for="cardType">Card Type</label>
+ <div class="controls">
+ <label class="radio" for="cardType-0">
+ {{view Ember.RadioButton name="cardTypeSelection" selectionBinding="cardTypeChoice" \
value="Visa"}} + Visa
+ </label>
+ <label class="radio" for="cardType-1">
+ {{view Ember.RadioButton name="cardTypeSelection" selectionBinding="cardTypeChoice" \
value="Master Card"}} + Master Card
+ </label>
+ <label class="radio" for="cardType-2">
+ {{view Ember.RadioButton name="cardTypeSelection" selectionBinding="cardTypeChoice" \
value="American Express"}} + American Express
+ </label>
+ <label class="radio" for="cardType-3">
+ {{view Ember.RadioButton name="cardTypeSelection" selectionBinding="cardTypeChoice" \
value="Dinners Club"}} + Dinners Club
+ </label>
+ </div>
</div>
- </div>
- <!-- Text input-->
- <div class="control-group">
- <label class="control-label" for="cardNumber">Number:</label>
- <div class="controls">
- {{input id="cardNumber" name="cardNumber" type="text" placeholder="Please type your card number" \
class="input-xlarge" value=cardNumber required=""}}
- {{#if cardNumberInvalid}}
- <p class="text-error">Your card number is not valid</p>
- {{/if}}
+ <!-- Text input-->
+ <div class="control-group">
+ <label class="control-label" for="cardName">Name on Card:</label>
+ <div class="controls">
+ {{input id="cardName" name="cardName" type="text" placeholder="Please type your full name" \
class="input-xlarge" value=cardName}} + {{#if cardNameInvalid}}
+ <p class="text-error">Your name is not valid</p>
+ {{/if}}
+ </div>
</div>
- </div>
- <!-- Text input-->
- <div class="control-group">
- <label class="control-label" for="cardCvc">CVC:</label>
- <div class="controls">
- {{input id="cardCvc" name="cardCvc" type="text" placeholder="Please type your cvc" \
class="input-xlarge" value=cardCvc required=""}}
- {{#if cardCvcInvalid}}
- <p class="text-error">Your cvc number is not valid</p>
- {{/if}}
+ <!-- Text input-->
+ <div class="control-group">
+ <label class="control-label" for="cardNumber">Number:</label>
+ <div class="controls">
+ {{input id="cardNumber" name="cardNumber" type="text" placeholder="Please type your card number" \
class="input-xlarge" value=cardNumber required=""}} + {{#if cardNumberInvalid}}
+ <p class="text-error">Your card number is not valid</p>
+ {{/if}}
+ </div>
</div>
- </div>
-
- <!-- Select Basic -->
- <div class="control-group">
- <label class="control-label" for="cardExpMonth">Expire Month:</label>
- <div class="controls">
- {{view Ember.Select
- content=cardExpMonthChoices
- value=cardExpMonthChoice
- }}
+ <!-- Text input-->
+ <div class="control-group">
+ <label class="control-label" for="cardCvc">CVC:</label>
+ <div class="controls">
+ {{input id="cardCvc" name="cardCvc" type="text" placeholder="Please type your cvc" \
class="input-xlarge" value=cardCvc required=""}} + {{#if cardCvcInvalid}}
+ <p class="text-error">Your cvc number is not valid</p>
+ {{/if}}
+ </div>
</div>
- </div>
- <!-- Select Basic -->
- <div class="control-group">
- <label class="control-label" for="cardExpYear">Expire Year:</label>
- <div class="controls">
+ <!-- Select Basic -->
+ <div class="control-group">
+ <label class="control-label" for="cardExpMonth">Expire Month:</label>
+ <div class="controls">
{{view Ember.Select
- content=cardExpYearChoices
- value=cardExpYearChoice
+ content=cardExpMonthChoices
+ value=cardExpMonthChoice
}}
- </div>
- </div>
- {{#if purchaseMethodMissing}}
- <!-- Button -->
- <div class="control-group">
- <label class="control-label" for="addCreditCard"></label>
- <div class="controls">
- <button id="addCreditCard" {{action 'updatePaymentMethod'}} name="addCreditCard" class="btn \
btn-primary">Add Your Credit Card</button> </div>
</div>
- {{else}}
- <!-- Button -->
+
+ <!-- Select Basic -->
<div class="control-group">
- <label class="control-label" for="updateCreditCard"></label>
+ <label class="control-label" for="cardExpYear">Expire Year:</label>
<div class="controls">
- <button id="updateCreditCard" name="updateCreditCard" class="btn btn-primary">Update Your Credit \
Card</button> + {{view Ember.Select
+ content=cardExpYearChoices
+ value=cardExpYearChoice
+ }}
</div>
</div>
- {{/if}}
- </fieldset>
+ {{#if purchaseMethodMissing}}
+ <!-- Button -->
+ <div class="control-group">
+ <label class="control-label" for="addCreditCard"></label>
+ <div class="controls">
+ <button id="addCreditCard" {{action 'updatePaymentMethod'}} name="addCreditCard" class="btn \
btn-primary">Add Your Credit Card</button> + </div>
+ </div>
+ {{else}}
+ <!-- Button -->
+ <div class="control-group">
+ <label class="control-label" for="updateCreditCard"></label>
+ <div class="controls">
+ <button id="updateCreditCard" name="updateCreditCard" class="btn btn-primary">Update Your \
Credit Card</button> + </div>
+ </div>
+ {{/if}}
+
+ </fieldset>
+ </form>
</script>
diff --git a/public/js/validator-min.js b/public/js/validator-min.js
new file mode 100644
index 0000000..7a1fa36
--- /dev/null
+++ b/public/js/validator-min.js
@@ -0,0 +1,23 @@
+/*!
+ * Copyright (c) 2010 Chris O'Hara <cohara87@gmail.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+!function(t,r){"function"==typeof define&&define.amd?define(["exports"],r):"object"==typeof \
exports?r(exports):r(t)}(this,function(t){function \
r(t){if(/^(\d?\d?\d)\.(\d?\d?\d)\.(\d?\d?\d)\.(\d?\d?\d)$/.test(t)){var r=t.split(".").sort();return \
r[3]>255?!1:!0}return!1}function \
i(t){return/^::|^::1|^([a-fA-F0-9]{1,4}::?){1,7}([a-fA-F0-9]{1,4})$/.test(t)?!0:!1}function e(t){if(t \
instanceof Date)return t;var r=Date.parse(t);return isNaN(r)?null:new Date(r)}var \
s={" ":"\u00a0","¡":"\u00a1","¢":"\u00a2","£":"\u00a3","¤":"\u20ac","¥":" \
\u00a5","¦":"\u0160","§":"\u00a7","¨":"\u0161","©":"\u00a9","ª":"\u00aa","« \
;":"\u00ab","¬":"\u00ac","­":"\u00ad","®":"\u00ae","¯":"\u00af","°":"\u00b0","± \
;":"\u00b1","²":"\u00b2","³":"\u00b3","´":"\u017d","µ":"\u00b5","¶":"\u00b6","& \
middot;":"\u00b7","¸":"\u017e","¹":"\u00b9","º":"\u00ba","»":"\u00bb","¼":"\u \
0152","½":"\u0153","¾":"\u0178","¿":"\u00bf","À":"\u00c0","Á":"\u00c1", \
"Â":"\u00c2","Ã":"\u00c3","Ä":"\u00c4","Å":"\u00c5","Æ":"\u00c6","Ç": \
"\u00c7","È":"\u00c8","É":"\u00c9","Ê":"\u00ca","Ë":"\u00cb","Ì":"\u00cc", \
"Í":"\u00cd","Î":"\u00ce","Ï":"\u00cf","Ð":"\u00d0","Ñ":"\u00d1","Ò":" \
\u00d2","Ó":"\u00d3","Ô":"\u00d4","Õ":"\u00d5","Ö":"\u00d6","×":"\u00d7","& \
Oslash;":"\u00d8","Ù":"\u00d9","Ú":"\u00da","Û":"\u00db","Ü":"\u00dc","Ý": \
"\u00dd","Þ":"\u00de","ß":"\u00df","à":"\u00e0","á":"\u00e1","â":"\u00e2", \
"ã":"\u00e3","ä":"\u00e4","å":"\u00e5","æ":"\u00e6","ç":"\u00e7","è" \
:"\u00e8","é":"\u00e9","ê":"\u00ea","ë":"\u00eb","ì":"\u00ec","í":"\u00ed" \
,"î":"\u00ee","ï":"\u00ef","ð":"\u00f0","ñ":"\u00f1","ò":"\u00f2","ó": \
"\u00f3","ô":"\u00f4","õ":"\u00f5","ö":"\u00f6","÷":"\u00f7","ø":"\u00f8", \
"ù":"\u00f9","ú":"\u00fa","û":"\u00fb","ü":"\u00fc","ý":"\u00fd","þ" \
:"\u00fe","ÿ":"\u00ff",""":'"',"<":"<",">":">","'":"'","−":"\u2212","ˆ":"\ \
u02c6","˜":"\u02dc","Š":"\u0160","‹":"\u2039","Œ":"\u0152","‘":"\u2018","& \
rsquo;":"\u2019","“":"\u201c","”":"\u201d","•":"\u2022","–":"\u2013","—":"\u2 \
014","™":"\u2122","š":"\u0161","›":"\u203a","œ":"\u0153","Ÿ":"\u0178","&fno \
f;":"\u0192","Α":"\u0391","Β":"\u0392","Γ":"\u0393","Δ":"\u0394","Ε":"\u039 \
5","Ζ":"\u0396","Η":"\u0397","Θ":"\u0398","Ι":"\u0399","Κ":"\u039a","Λ":" \
\u039b","Μ":"\u039c","Ν":"\u039d","Ξ":"\u039e","Ο":"\u039f","Π":"\u03a0","Ρ":"\u03 \
a1","Σ":"\u03a3","Τ":"\u03a4","Υ":"\u03a5","Φ":"\u03a6","Χ":"\u03a7","Ψ":"\u \
03a8","Ω":"\u03a9","α":"\u03b1","β":"\u03b2","γ":"\u03b3","δ":"\u03b4","&epsi \
lon;":"\u03b5","ζ":"\u03b6","η":"\u03b7","θ":"\u03b8","ι":"\u03b9","κ":"\u03ba", \
"λ":"\u03bb","μ":"\u03bc","ν":"\u03bd","ξ":"\u03be","ο":"\u03bf","π":"\u03c0"," \
ρ":"\u03c1","ς":"\u03c2","σ":"\u03c3","τ":"\u03c4","υ":"\u03c5","φ":"\u03 \
c6","χ":"\u03c7","ψ":"\u03c8","ω":"\u03c9","ϑ":"\u03d1","ϒ":"\u03d2","ϖ": \
"\u03d6"," ":"\u2002"," ":"\u2003"," ":"\u2009","‌":"\u200c","‍":"\u200d","‎ \
":"\u200e","‏":"\u200f","‚":"\u201a","„":"\u201e","†":"\u2020","‡":"\u2021", \
"…":"\u2026","‰":"\u2030","′":"\u2032","″":"\u2033","‾":"\u203e","⁄" \
:"\u2044","€":"\u20ac","ℑ":"\u2111","℘":"\u2118","ℜ":"\u211c","ℵ":"\u2135", \
"←":"\u2190","↑":"\u2191","→":"\u2192","↓":"\u2193","↔":"\u2194","↵":"\u21b \
5","⇐":"\u21d0","⇑":"\u21d1","⇒":"\u21d2","⇓":"\u21d3","⇔":"\u21d4","∀":"\ \
u2200","∂":"\u2202","∃":"\u2203","∅":"\u2205","∇":"\u2207","∈":"\u2208","¬i \
n;":"\u2209","∋":"\u220b","∏":"\u220f","∑":"\u2211","∗":"\u2217","√":"\u221a","&p \
rop;":"\u221d","∞":"\u221e","∠":"\u2220","∧":"\u2227","∨":"\u2228","∩":"\u2229","&cup \
;":"\u222a","∫":"\u222b","∴":"\u2234","∼":"\u223c","≅":"\u2245","≈":"\u2248","&n \
e;":"\u2260","≡":"\u2261","≤":"\u2264","≥":"\u2265","⊂":"\u2282","⊃":"\u2283","⊄" \
:"\u2284","⊆":"\u2286","⊇":"\u2287","⊕":"\u2295","⊗":"\u2297","⊥":"\u22a5","&s \
dot;":"\u22c5","⌈":"\u2308","⌉":"\u2309","⌊":"\u230a","⌋":"\u230b","⟨":"\u2 \
329","⟩":"\u232a","◊":"\u25ca","♠":"\u2660","♣":"\u2663","♥":"\u2665","♦":"\u2666"},o=function(t){if(!~t.indexOf("&"))return \
t;for(var r in s)t=t.replace(new RegExp(r,"g"),s[r]);return \
t=t.replace(/&#x(0*[0-9a-f]{2,5});?/gi,function(t,r){return \
String.fromCharCode(parseInt(+r,16))}),t=t.replace(/&#([0-9]{2,4});?/gi,function(t,r){return \
String.fromCharCode(+r)}),t=t.replace(/&/g,"&")},n=function(t){t=t.replace(/&/g,"&"),t=t.replace(/'/g,"'");for(var \
r in s)t=t.replace(new RegExp(s[r],"g"),r);return t};t.entities={encode:n,decode:o};var \
a=t.Validator=function(){};a.prototype.check=function(t,r){return this.str="undefined"==typeof \
t||null===t||isNaN(t)&&void \
0===t.length?"":t+"",this.msg=r,this._errors=this._errors||[],this},a.prototype.validate=a.prototype.check,a.prototype.assert=a.prototype.check,a.prototype.error=function(t){throw \
new Error(t)},a.prototype.isAfter=function(t){t=t||new Date;var r=e(this.str),i=e(t);return \
r&&i&&r>=i?this:this.error(this.msg||"Invalid date")},a.prototype.isBefore=function(t){t=t||new Date;var \
r=e(this.str),i=e(t);return r&&i&&i>=r?this:this.error(this.msg||"Invalid \
date")},a.prototype.isEmail=function(){return \
this.str.match(/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+ \
@(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!\.)){0,61}[a-zA-Z0-9]?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!$)){0,61}[ \
a-zA-Z0-9]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/)?this:this.error(this.msg||"Invalid \
email")},a.prototype.isCreditCard=function(){if(this.str=this.str.replace(/[^0-9]+/g,""),!this.str.match(/ \
^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$/))return \
this.error(this.msg||"Invalid credit card");for(var \
t,r,i=0,e=!1,s=this.length-1;s>=0;s--)t=this.substring(s,s+1),r=parseInt(t,10),e?(r*=2,i+=r>=10?r%10+1:r):i+=r,e=e?!1:!0;return \
i%10!==0?this.error(this.msg||"Invalid credit \
card"):this},a.prototype.isUrl=function(){return!this.str.match(/^(?!mailto:)(?:(?:https?|ftp):\/\/)?(?:\S \
+(?::\S*)?@)?(?:(?:(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\ \
d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uff \
ff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))|localhost)(?::\d{2,5})?(?:\/[^\s]*)?$/i)||this.str.length>2083?this.error(this.msg||"Invalid \
URL"):this},a.prototype.isIPv4=function(){return r(this.str)?this:this.error(this.msg||"Invalid \
IP")},a.prototype.isIPv6=function(){return i(this.str)?this:this.error(this.msg||"Invalid \
IP")},a.prototype.isIP=function(){return r(this.str)||i(this.str)?this:this.error(this.msg||"Invalid \
IP")},a.prototype.isAlpha=function(){return \
this.str.match(/^[a-zA-Z]+$/)?this:this.error(this.msg||"Invalid \
characters")},a.prototype.isAlphanumeric=function(){return \
this.str.match(/^[a-zA-Z0-9]+$/)?this:this.error(this.msg||"Invalid \
characters")},a.prototype.isNumeric=function(){return \
this.str.match(/^-?[0-9]+$/)?this:this.error(this.msg||"Invalid \
number")},a.prototype.isHexadecimal=function(){return \
this.str.match(/^[0-9a-fA-F]+$/)?this:this.error(this.msg||"Invalid \
hexadecimal")},a.prototype.isHexColor=function(){return \
this.str.match(/^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/)?this:this.error(this.msg||"Invalid \
hexcolor")},a.prototype.isLowercase=function(){return \
this.str!==this.str.toLowerCase()?this.error(this.msg||"Invalid \
characters"):this},a.prototype.isUppercase=function(){return \
this.str!==this.str.toUpperCase()?this.error(this.msg||"Invalid \
characters"):this},a.prototype.isInt=function(){return \
this.str.match(/^(?:-?(?:0|[1-9][0-9]*))$/)?this:this.error(this.msg||"Invalid \
integer")},a.prototype.isDecimal=function(){return \
this.str.match(/^(?:-?(?:0|[1-9][0-9]*))?(?:\.[0-9]*)?$/)?this:this.error(this.msg||"Invalid \
decimal")},a.prototype.isDivisibleBy=function(t){return \
parseFloat(this.str)%parseInt(t,10)===0},a.prototype.isFloat=function(){return \
this.isDecimal()},a.prototype.notNull=function(){return""===this.str?this.error(this.msg||"String is \
empty"):this},a.prototype.isNull=function(){return""!==this.str?this.error(this.msg||"String is not \
empty"):this},a.prototype.notEmpty=function(){return \
this.str.match(/^[\s\t\r\n]*$/)?this.error(this.msg||"String is \
whitespace"):this},a.prototype.equals=function(t){return this.str!=t?this.error(this.msg||"Not \
equal"):this},a.prototype.contains=function(t){return-1!==this.str.indexOf(t)&&t?this:this.error(this.msg||"Invalid \
characters")},a.prototype.notContains=function(t){return \
this.str.indexOf(t)>=0?this.error(this.msg||"Invalid \
characters"):this},a.prototype.regex=a.prototype.is=function(t,r){return"RegExp"!==Object.prototype.toString.call(t).slice(8,-1)&&(t=new \
RegExp(t,r)),this.str.match(t)?this:this.error(this.msg||"Invalid \
characters")},a.prototype.notRegex=a.prototype.not=function(t,r){return"RegExp"!==Object.prototype.toString.call(t).slice(8,-1)&&(t=new \
RegExp(t,r)),this.str.match(t)&&this.error(this.msg||"Invalid \
characters"),this},a.prototype.len=function(t,r){return this.str.length<t?this.error(this.msg||"String is \
too small"):void 0!==typeof r&&this.str.length>r?this.error(this.msg||"String is too \
large"):this},a.prototype.isUUID=function(t){var r;return \
r=3==t||"v3"==t?/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i:4==t||"v4"==t?/^[0-9A-F \
]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i:5==t||"v5"==t?/^[0-9A-F]{8}-[0-9A-F]{4}-5[ \
0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i,this.str.match(r)?this:this.error(this.msg||"Not \
a UUID")},a.prototype.isUUIDv3=function(){return this.isUUID(3)},a.prototype.isUUIDv4=function(){return \
this.isUUID(4)},a.prototype.isUUIDv5=function(){return this.isUUID(5)},a.prototype.isDate=function(){var \
t=Date.parse(this.str);return isNaN(t)?this.error(this.msg||"Not a \
date"):this},a.prototype.isIn=function(t){return t&&"function"==typeof \
t.indexOf?~t.indexOf(this.str)?this:this.error(this.msg||"Unexpected \
value"):this.error(this.msg||"Invalid in() argument")},a.prototype.notIn=function(t){return \
t&&"function"==typeof t.indexOf?-1!==t.indexOf(this.str)?this.error(this.msg||"Unexpected \
value"):this:this.error(this.msg||"Invalid notIn() argument")},a.prototype.min=function(t){var \
r=parseFloat(this.str);return!isNaN(r)&&t>r?this.error(this.msg||"Invalid \
number"):this},a.prototype.max=function(t){var \
r=parseFloat(this.str);return!isNaN(r)&&r>t?this.error(this.msg||"Invalid number"):this};var \
h=t.Filter=function(){},u="\\r\\n\\t\\s";return \
h.prototype.modify=function(t){this.str=t},h.prototype.convert=h.prototype.sanitize=function(t){return \
this.str=null==t?"":t+"",this},h.prototype.entityDecode=function(){return \
this.modify(o(this.str)),this.str},h.prototype.entityEncode=function(){return \
this.modify(n(this.str)),this.str},h.prototype.escape=function(){return \
this.modify(this.str.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")),this.str},h.prototype.ltrim=function(t){return \
t=t||u,this.modify(this.str.replace(new \
RegExp("^["+t+"]+","g"),"")),this.str},h.prototype.rtrim=function(t){return \
t=t||u,this.modify(this.str.replace(new \
RegExp("["+t+"]+$","g"),"")),this.str},h.prototype.trim=function(t){return \
t=t||u,this.modify(this.str.replace(new \
RegExp("^["+t+"]+|["+t+"]+$","g"),"")),this.str},h.prototype.ifNull=function(t){return \
this.str&&""!==this.str||this.modify(t),this.str},h.prototype.toFloat=function(){return \
this.modify(parseFloat(this.str)),this.str},h.prototype.toInt=function(t){return \
t=t||10,this.modify(parseInt(this.str,t)),this.str},h.prototype.toBoolean=function(){return \
this.str&&"0"!=this.str&&"false"!=this.str&&""!=this.str?this.modify(!0):this.modify(!1),this.str},h.proto \
type.toBooleanStrict=function(){return"1"==this.str||"true"==this.str?this.modify(!0):this.modify(!1),this.str},t.sanitize=t.convert=function(r){var \
i=new t.Filter;return i.sanitize(r)},t.check=t.validate=t.assert=function(r,i){var e=new \
t.Validator;return e.check(r,i)},t});
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic