/branches/v5.0-ouadji/api/js/dojo/src/validate/__package__.js |
---|
New file |
0,0 → 1,16 |
/* |
Copyright (c) 2004-2006, The Dojo Foundation |
All Rights Reserved. |
Licensed under the Academic Free License version 2.1 or above OR the |
modified BSD license. For more information on Dojo licensing, see: |
http://dojotoolkit.org/community/licensing.shtml |
*/ |
dojo.require("dojo.validate"); |
dojo.kwCompoundRequire({common:["dojo.validate.check", "dojo.validate.datetime", "dojo.validate.de", "dojo.validate.jp", "dojo.validate.us", "dojo.validate.web"]}); |
dojo.provide("dojo.validate.*"); |
/branches/v5.0-ouadji/api/js/dojo/src/validate/us.js |
---|
New file |
0,0 → 1,34 |
/* |
Copyright (c) 2004-2006, The Dojo Foundation |
All Rights Reserved. |
Licensed under the Academic Free License version 2.1 or above OR the |
modified BSD license. For more information on Dojo licensing, see: |
http://dojotoolkit.org/community/licensing.shtml |
*/ |
dojo.provide("dojo.validate.us"); |
dojo.require("dojo.validate.common"); |
dojo.validate.us.isCurrency = function (value, flags) { |
return dojo.validate.isCurrency(value, flags); |
}; |
dojo.validate.us.isState = function (value, flags) { |
var re = new RegExp("^" + dojo.regexp.us.state(flags) + "$", "i"); |
return re.test(value); |
}; |
dojo.validate.us.isPhoneNumber = function (value) { |
var flags = {format:["###-###-####", "(###) ###-####", "(###) ### ####", "###.###.####", "###/###-####", "### ### ####", "###-###-#### x#???", "(###) ###-#### x#???", "(###) ### #### x#???", "###.###.#### x#???", "###/###-#### x#???", "### ### #### x#???", "##########"]}; |
return dojo.validate.isNumberFormat(value, flags); |
}; |
dojo.validate.us.isSocialSecurityNumber = function (value) { |
var flags = {format:["###-##-####", "### ## ####", "#########"]}; |
return dojo.validate.isNumberFormat(value, flags); |
}; |
dojo.validate.us.isZipCode = function (value) { |
var flags = {format:["#####-####", "##### ####", "#########", "#####"]}; |
return dojo.validate.isNumberFormat(value, flags); |
}; |
/branches/v5.0-ouadji/api/js/dojo/src/validate/common.js |
---|
New file |
0,0 → 1,96 |
/* |
Copyright (c) 2004-2006, The Dojo Foundation |
All Rights Reserved. |
Licensed under the Academic Free License version 2.1 or above OR the |
modified BSD license. For more information on Dojo licensing, see: |
http://dojotoolkit.org/community/licensing.shtml |
*/ |
dojo.provide("dojo.validate.common"); |
dojo.require("dojo.regexp"); |
dojo.validate.isText = function (value, flags) { |
flags = (typeof flags == "object") ? flags : {}; |
if (/^\s*$/.test(value)) { |
return false; |
} |
if (typeof flags.length == "number" && flags.length != value.length) { |
return false; |
} |
if (typeof flags.minlength == "number" && flags.minlength > value.length) { |
return false; |
} |
if (typeof flags.maxlength == "number" && flags.maxlength < value.length) { |
return false; |
} |
return true; |
}; |
dojo.validate.isInteger = function (value, flags) { |
var re = new RegExp("^" + dojo.regexp.integer(flags) + "$"); |
return re.test(value); |
}; |
dojo.validate.isRealNumber = function (value, flags) { |
var re = new RegExp("^" + dojo.regexp.realNumber(flags) + "$"); |
return re.test(value); |
}; |
dojo.validate.isCurrency = function (value, flags) { |
var re = new RegExp("^" + dojo.regexp.currency(flags) + "$"); |
return re.test(value); |
}; |
dojo.validate._isInRangeCache = {}; |
dojo.validate.isInRange = function (value, flags) { |
value = value.replace(dojo.lang.has(flags, "separator") ? flags.separator : ",", "", "g").replace(dojo.lang.has(flags, "symbol") ? flags.symbol : "$", ""); |
if (isNaN(value)) { |
return false; |
} |
flags = (typeof flags == "object") ? flags : {}; |
var max = (typeof flags.max == "number") ? flags.max : Infinity; |
var min = (typeof flags.min == "number") ? flags.min : -Infinity; |
var dec = (typeof flags.decimal == "string") ? flags.decimal : "."; |
var cache = dojo.validate._isInRangeCache; |
var cacheIdx = value + "max" + max + "min" + min + "dec" + dec; |
if (typeof cache[cacheIdx] != "undefined") { |
return cache[cacheIdx]; |
} |
var pattern = "[^" + dec + "\\deE+-]"; |
value = value.replace(RegExp(pattern, "g"), ""); |
value = value.replace(/^([+-]?)(\D*)/, "$1"); |
value = value.replace(/(\D*)$/, ""); |
pattern = "(\\d)[" + dec + "](\\d)"; |
value = value.replace(RegExp(pattern, "g"), "$1.$2"); |
value = Number(value); |
if (value < min || value > max) { |
cache[cacheIdx] = false; |
return false; |
} |
cache[cacheIdx] = true; |
return true; |
}; |
dojo.validate.isNumberFormat = function (value, flags) { |
var re = new RegExp("^" + dojo.regexp.numberFormat(flags) + "$", "i"); |
return re.test(value); |
}; |
dojo.validate.isValidLuhn = function (value) { |
var sum, parity, curDigit; |
if (typeof value != "string") { |
value = String(value); |
} |
value = value.replace(/[- ]/g, ""); |
parity = value.length % 2; |
sum = 0; |
for (var i = 0; i < value.length; i++) { |
curDigit = parseInt(value.charAt(i)); |
if (i % 2 == parity) { |
curDigit *= 2; |
} |
if (curDigit > 9) { |
curDigit -= 9; |
} |
sum += curDigit; |
} |
return !(sum % 10); |
}; |
/branches/v5.0-ouadji/api/js/dojo/src/validate/de.js |
---|
New file |
0,0 → 1,19 |
/* |
Copyright (c) 2004-2006, The Dojo Foundation |
All Rights Reserved. |
Licensed under the Academic Free License version 2.1 or above OR the |
modified BSD license. For more information on Dojo licensing, see: |
http://dojotoolkit.org/community/licensing.shtml |
*/ |
dojo.provide("dojo.validate.de"); |
dojo.require("dojo.validate.common"); |
dojo.validate.isGermanCurrency = function (value) { |
var flags = {symbol:"\u20ac", placement:"after", signPlacement:"begin", decimal:",", separator:"."}; |
return dojo.validate.isCurrency(value, flags); |
}; |
/branches/v5.0-ouadji/api/js/dojo/src/validate/jp.js |
---|
New file |
0,0 → 1,19 |
/* |
Copyright (c) 2004-2006, The Dojo Foundation |
All Rights Reserved. |
Licensed under the Academic Free License version 2.1 or above OR the |
modified BSD license. For more information on Dojo licensing, see: |
http://dojotoolkit.org/community/licensing.shtml |
*/ |
dojo.provide("dojo.validate.jp"); |
dojo.require("dojo.validate.common"); |
dojo.validate.isJapaneseCurrency = function (value) { |
var flags = {symbol:"\xa5", fractional:false}; |
return dojo.validate.isCurrency(value, flags); |
}; |
/branches/v5.0-ouadji/api/js/dojo/src/validate/datetime.js |
---|
New file |
0,0 → 1,92 |
/* |
Copyright (c) 2004-2006, The Dojo Foundation |
All Rights Reserved. |
Licensed under the Academic Free License version 2.1 or above OR the |
modified BSD license. For more information on Dojo licensing, see: |
http://dojotoolkit.org/community/licensing.shtml |
*/ |
dojo.provide("dojo.validate.datetime"); |
dojo.require("dojo.validate.common"); |
dojo.validate.isValidTime = function (value, flags) { |
dojo.deprecated("dojo.validate.datetime", "use dojo.date.parse instead", "0.5"); |
var re = new RegExp("^" + dojo.regexp.time(flags) + "$", "i"); |
return re.test(value); |
}; |
dojo.validate.is12HourTime = function (value) { |
dojo.deprecated("dojo.validate.datetime", "use dojo.date.parse instead", "0.5"); |
return dojo.validate.isValidTime(value, {format:["h:mm:ss t", "h:mm t"]}); |
}; |
dojo.validate.is24HourTime = function (value) { |
dojo.deprecated("dojo.validate.datetime", "use dojo.date.parse instead", "0.5"); |
return dojo.validate.isValidTime(value, {format:["HH:mm:ss", "HH:mm"]}); |
}; |
dojo.validate.isValidDate = function (dateValue, format) { |
dojo.deprecated("dojo.validate.datetime", "use dojo.date.parse instead", "0.5"); |
if (typeof format == "object" && typeof format.format == "string") { |
format = format.format; |
} |
if (typeof format != "string") { |
format = "MM/DD/YYYY"; |
} |
var reLiteral = format.replace(/([$^.*+?=!:|\/\\\(\)\[\]\{\}])/g, "\\$1"); |
reLiteral = reLiteral.replace("YYYY", "([0-9]{4})"); |
reLiteral = reLiteral.replace("MM", "(0[1-9]|10|11|12)"); |
reLiteral = reLiteral.replace("M", "([1-9]|10|11|12)"); |
reLiteral = reLiteral.replace("DDD", "(00[1-9]|0[1-9][0-9]|[12][0-9][0-9]|3[0-5][0-9]|36[0-6])"); |
reLiteral = reLiteral.replace("DD", "(0[1-9]|[12][0-9]|30|31)"); |
reLiteral = reLiteral.replace("D", "([1-9]|[12][0-9]|30|31)"); |
reLiteral = reLiteral.replace("ww", "(0[1-9]|[1-4][0-9]|5[0-3])"); |
reLiteral = reLiteral.replace("d", "([1-7])"); |
reLiteral = "^" + reLiteral + "$"; |
var re = new RegExp(reLiteral); |
if (!re.test(dateValue)) { |
return false; |
} |
var year = 0, month = 1, date = 1, dayofyear = 1, week = 1, day = 1; |
var tokens = format.match(/(YYYY|MM|M|DDD|DD|D|ww|d)/g); |
var values = re.exec(dateValue); |
for (var i = 0; i < tokens.length; i++) { |
switch (tokens[i]) { |
case "YYYY": |
year = Number(values[i + 1]); |
break; |
case "M": |
case "MM": |
month = Number(values[i + 1]); |
break; |
case "D": |
case "DD": |
date = Number(values[i + 1]); |
break; |
case "DDD": |
dayofyear = Number(values[i + 1]); |
break; |
case "ww": |
week = Number(values[i + 1]); |
break; |
case "d": |
day = Number(values[i + 1]); |
break; |
} |
} |
var leapyear = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); |
if (date == 31 && (month == 4 || month == 6 || month == 9 || month == 11)) { |
return false; |
} |
if (date >= 30 && month == 2) { |
return false; |
} |
if (date == 29 && month == 2 && !leapyear) { |
return false; |
} |
if (dayofyear == 366 && !leapyear) { |
return false; |
} |
return true; |
}; |
/branches/v5.0-ouadji/api/js/dojo/src/validate/check.js |
---|
New file |
0,0 → 1,234 |
/* |
Copyright (c) 2004-2006, The Dojo Foundation |
All Rights Reserved. |
Licensed under the Academic Free License version 2.1 or above OR the |
modified BSD license. For more information on Dojo licensing, see: |
http://dojotoolkit.org/community/licensing.shtml |
*/ |
dojo.provide("dojo.validate.check"); |
dojo.require("dojo.validate.common"); |
dojo.require("dojo.lang.common"); |
dojo.validate.check = function (form, profile) { |
var missing = []; |
var invalid = []; |
var results = {isSuccessful:function () { |
return (!this.hasInvalid() && !this.hasMissing()); |
}, hasMissing:function () { |
return (missing.length > 0); |
}, getMissing:function () { |
return missing; |
}, isMissing:function (elemname) { |
for (var i = 0; i < missing.length; i++) { |
if (elemname == missing[i]) { |
return true; |
} |
} |
return false; |
}, hasInvalid:function () { |
return (invalid.length > 0); |
}, getInvalid:function () { |
return invalid; |
}, isInvalid:function (elemname) { |
for (var i = 0; i < invalid.length; i++) { |
if (elemname == invalid[i]) { |
return true; |
} |
} |
return false; |
}}; |
if (profile.trim instanceof Array) { |
for (var i = 0; i < profile.trim.length; i++) { |
var elem = form[profile.trim[i]]; |
if (dj_undef("type", elem) || elem.type != "text" && elem.type != "textarea" && elem.type != "password") { |
continue; |
} |
elem.value = elem.value.replace(/(^\s*|\s*$)/g, ""); |
} |
} |
if (profile.uppercase instanceof Array) { |
for (var i = 0; i < profile.uppercase.length; i++) { |
var elem = form[profile.uppercase[i]]; |
if (dj_undef("type", elem) || elem.type != "text" && elem.type != "textarea" && elem.type != "password") { |
continue; |
} |
elem.value = elem.value.toUpperCase(); |
} |
} |
if (profile.lowercase instanceof Array) { |
for (var i = 0; i < profile.lowercase.length; i++) { |
var elem = form[profile.lowercase[i]]; |
if (dj_undef("type", elem) || elem.type != "text" && elem.type != "textarea" && elem.type != "password") { |
continue; |
} |
elem.value = elem.value.toLowerCase(); |
} |
} |
if (profile.ucfirst instanceof Array) { |
for (var i = 0; i < profile.ucfirst.length; i++) { |
var elem = form[profile.ucfirst[i]]; |
if (dj_undef("type", elem) || elem.type != "text" && elem.type != "textarea" && elem.type != "password") { |
continue; |
} |
elem.value = elem.value.replace(/\b\w+\b/g, function (word) { |
return word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase(); |
}); |
} |
} |
if (profile.digit instanceof Array) { |
for (var i = 0; i < profile.digit.length; i++) { |
var elem = form[profile.digit[i]]; |
if (dj_undef("type", elem) || elem.type != "text" && elem.type != "textarea" && elem.type != "password") { |
continue; |
} |
elem.value = elem.value.replace(/\D/g, ""); |
} |
} |
if (profile.required instanceof Array) { |
for (var i = 0; i < profile.required.length; i++) { |
if (!dojo.lang.isString(profile.required[i])) { |
continue; |
} |
var elem = form[profile.required[i]]; |
if (!dj_undef("type", elem) && (elem.type == "text" || elem.type == "textarea" || elem.type == "password") && /^\s*$/.test(elem.value)) { |
missing[missing.length] = elem.name; |
} else { |
if (!dj_undef("type", elem) && (elem.type == "select-one" || elem.type == "select-multiple") && (elem.selectedIndex == -1 || /^\s*$/.test(elem.options[elem.selectedIndex].value))) { |
missing[missing.length] = elem.name; |
} else { |
if (elem instanceof Array) { |
var checked = false; |
for (var j = 0; j < elem.length; j++) { |
if (elem[j].checked) { |
checked = true; |
} |
} |
if (!checked) { |
missing[missing.length] = elem[0].name; |
} |
} |
} |
} |
} |
} |
if (profile.required instanceof Array) { |
for (var i = 0; i < profile.required.length; i++) { |
if (!dojo.lang.isObject(profile.required[i])) { |
continue; |
} |
var elem, numRequired; |
for (var name in profile.required[i]) { |
elem = form[name]; |
numRequired = profile.required[i][name]; |
} |
if (elem instanceof Array) { |
var checked = 0; |
for (var j = 0; j < elem.length; j++) { |
if (elem[j].checked) { |
checked++; |
} |
} |
if (checked < numRequired) { |
missing[missing.length] = elem[0].name; |
} |
} else { |
if (!dj_undef("type", elem) && elem.type == "select-multiple") { |
var selected = 0; |
for (var j = 0; j < elem.options.length; j++) { |
if (elem.options[j].selected && !/^\s*$/.test(elem.options[j].value)) { |
selected++; |
} |
} |
if (selected < numRequired) { |
missing[missing.length] = elem.name; |
} |
} |
} |
} |
} |
if (dojo.lang.isObject(profile.dependencies) || dojo.lang.isObject(profile.dependancies)) { |
if (profile["dependancies"]) { |
dojo.deprecated("dojo.validate.check", "profile 'dependancies' is deprecated, please use " + "'dependencies'", "0.5"); |
profile.dependencies = profile.dependancies; |
} |
for (name in profile.dependencies) { |
var elem = form[name]; |
if (dj_undef("type", elem)) { |
continue; |
} |
if (elem.type != "text" && elem.type != "textarea" && elem.type != "password") { |
continue; |
} |
if (/\S+/.test(elem.value)) { |
continue; |
} |
if (results.isMissing(elem.name)) { |
continue; |
} |
var target = form[profile.dependencies[name]]; |
if (target.type != "text" && target.type != "textarea" && target.type != "password") { |
continue; |
} |
if (/^\s*$/.test(target.value)) { |
continue; |
} |
missing[missing.length] = elem.name; |
} |
} |
if (dojo.lang.isObject(profile.constraints)) { |
for (name in profile.constraints) { |
var elem = form[name]; |
if (!elem) { |
continue; |
} |
if (!dj_undef("tagName", elem) && (elem.tagName.toLowerCase().indexOf("input") >= 0 || elem.tagName.toLowerCase().indexOf("textarea") >= 0) && /^\s*$/.test(elem.value)) { |
continue; |
} |
var isValid = true; |
if (dojo.lang.isFunction(profile.constraints[name])) { |
isValid = profile.constraints[name](elem.value); |
} else { |
if (dojo.lang.isArray(profile.constraints[name])) { |
if (dojo.lang.isArray(profile.constraints[name][0])) { |
for (var i = 0; i < profile.constraints[name].length; i++) { |
isValid = dojo.validate.evaluateConstraint(profile, profile.constraints[name][i], name, elem); |
if (!isValid) { |
break; |
} |
} |
} else { |
isValid = dojo.validate.evaluateConstraint(profile, profile.constraints[name], name, elem); |
} |
} |
} |
if (!isValid) { |
invalid[invalid.length] = elem.name; |
} |
} |
} |
if (dojo.lang.isObject(profile.confirm)) { |
for (name in profile.confirm) { |
var elem = form[name]; |
var target = form[profile.confirm[name]]; |
if (dj_undef("type", elem) || dj_undef("type", target) || (elem.type != "text" && elem.type != "textarea" && elem.type != "password") || (target.type != elem.type) || (target.value == elem.value) || (results.isInvalid(elem.name)) || (/^\s*$/.test(target.value))) { |
continue; |
} |
invalid[invalid.length] = elem.name; |
} |
} |
return results; |
}; |
dojo.validate.evaluateConstraint = function (profile, constraint, fieldName, elem) { |
var isValidSomething = constraint[0]; |
var params = constraint.slice(1); |
params.unshift(elem.value); |
if (typeof isValidSomething != "undefined") { |
return isValidSomething.apply(null, params); |
} |
return false; |
}; |
/branches/v5.0-ouadji/api/js/dojo/src/validate/web.js |
---|
New file |
0,0 → 1,43 |
/* |
Copyright (c) 2004-2006, The Dojo Foundation |
All Rights Reserved. |
Licensed under the Academic Free License version 2.1 or above OR the |
modified BSD license. For more information on Dojo licensing, see: |
http://dojotoolkit.org/community/licensing.shtml |
*/ |
dojo.provide("dojo.validate.web"); |
dojo.require("dojo.validate.common"); |
dojo.validate.isIpAddress = function (value, flags) { |
var re = new RegExp("^" + dojo.regexp.ipAddress(flags) + "$", "i"); |
return re.test(value); |
}; |
dojo.validate.isUrl = function (value, flags) { |
var re = new RegExp("^" + dojo.regexp.url(flags) + "$", "i"); |
return re.test(value); |
}; |
dojo.validate.isEmailAddress = function (value, flags) { |
var re = new RegExp("^" + dojo.regexp.emailAddress(flags) + "$", "i"); |
return re.test(value); |
}; |
dojo.validate.isEmailAddressList = function (value, flags) { |
var re = new RegExp("^" + dojo.regexp.emailAddressList(flags) + "$", "i"); |
return re.test(value); |
}; |
dojo.validate.getEmailAddressList = function (value, flags) { |
if (!flags) { |
flags = {}; |
} |
if (!flags.listSeparator) { |
flags.listSeparator = "\\s;,"; |
} |
if (dojo.validate.isEmailAddressList(value, flags)) { |
return value.split(new RegExp("\\s*[" + flags.listSeparator + "]\\s*")); |
} |
return []; |
}; |
/branches/v5.0-ouadji/api/js/dojo/src/validate/creditCard.js |
---|
New file |
0,0 → 1,64 |
/* |
Copyright (c) 2004-2006, The Dojo Foundation |
All Rights Reserved. |
Licensed under the Academic Free License version 2.1 or above OR the |
modified BSD license. For more information on Dojo licensing, see: |
http://dojotoolkit.org/community/licensing.shtml |
*/ |
dojo.provide("dojo.validate.creditCard"); |
dojo.require("dojo.lang.common"); |
dojo.require("dojo.validate.common"); |
dojo.validate.isValidCreditCard = function (value, ccType) { |
if (value && ccType && ((ccType.toLowerCase() == "er" || dojo.validate.isValidLuhn(value)) && (dojo.validate.isValidCreditCardNumber(value, ccType.toLowerCase())))) { |
return true; |
} |
return false; |
}; |
dojo.validate.isValidCreditCardNumber = function (value, ccType) { |
if (typeof value != "string") { |
value = String(value); |
} |
value = value.replace(/[- ]/g, ""); |
var results = []; |
var cardinfo = {"mc":"5[1-5][0-9]{14}", "ec":"5[1-5][0-9]{14}", "vi":"4([0-9]{12}|[0-9]{15})", "ax":"3[47][0-9]{13}", "dc":"3(0[0-5][0-9]{11}|[68][0-9]{12})", "bl":"3(0[0-5][0-9]{11}|[68][0-9]{12})", "di":"6011[0-9]{12}", "jcb":"(3[0-9]{15}|(2131|1800)[0-9]{11})", "er":"2(014|149)[0-9]{11}"}; |
if (ccType && dojo.lang.has(cardinfo, ccType.toLowerCase())) { |
return Boolean(value.match(cardinfo[ccType.toLowerCase()])); |
} else { |
for (var p in cardinfo) { |
if (value.match("^" + cardinfo[p] + "$") != null) { |
results.push(p); |
} |
} |
return (results.length) ? results.join("|") : false; |
} |
}; |
dojo.validate.isValidCvv = function (value, ccType) { |
if (typeof value != "string") { |
value = String(value); |
} |
var format; |
switch (ccType.toLowerCase()) { |
case "mc": |
case "ec": |
case "vi": |
case "di": |
format = "###"; |
break; |
case "ax": |
format = "####"; |
break; |
default: |
return false; |
} |
var flags = {format:format}; |
if ((value.length == format.length) && (dojo.validate.isNumberFormat(value, flags))) { |
return true; |
} |
return false; |
}; |