commons-validator-1.4.0-src/LICENSE.txt 100644 765 0 26136 11711227702 20656 0 ustar simonetripodi wheel 0 0
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
commons-validator-1.4.0-src/NOTICE.txt 100644 765 0 262 11711227702 20505 0 ustar simonetripodi wheel 0 0 Apache Commons Validator
Copyright 2001-2012 The Apache Software Foundation
This product includes software developed by
The Apache Software Foundation (http://www.apache.org/).
commons-validator-1.4.0-src/RELEASE-NOTES.txt 100644 765 0 14011 11711227702 21527 0 ustar simonetripodi wheel 0 0
$Id: RELEASE-NOTES.txt 1236877 2012-01-27 20:36:39Z sebb $
Commons Validator Package
Version 1.4.0
Release Notes
INTRODUCTION
============
This is a maintenance release with improvements. New projects are encouraged to
use this release of Commons Validator.
IMPORTANT NOTES
================
BREAKING CHANGES:
* NONE.
DEPENDENCIES
=============
The dependencies for Validator 1.4 have only one change since the 1.3.1
release, in that the Jakarta ORO dependency has been removed (VALIDATOR-193).
For the current list of dependencies, please see
http://commons.apache.org/validator/dependencies.html
BUGS FROM PREVIOUS RELEASE
===========================
* [VALIDATOR-216] - UrlValidator rejects top-level domains (TLDs) with
more than 4 characters
* [VALIDATOR-218] - UrlValidator fail when path contains "(" / ")"
* [VALIDATOR-220] - EmailValidator fails with ArrayIndexOutOfBoundsException
on domain names longer than 10 segments
* [VALIDATOR-223] - Move the trim() function from validateRequired.js to
validateUtilities.js
* [VALIDATOR-271] - gmail testing addresses do not validate
* [VALIDATOR-276] - isValidURL call returns false for file scheme/protocol
when URL is correct
* [VALIDATOR-282] - formatDate(String value, Locale locale) in
GenericTypeValidator uses DateFormat.SHORT instead of
DateFormat.DEFAULT
* [VALIDATOR-286] - isValid method for EmailValidator should return false
for domain with special characters only
* [VALIDATOR-289] - UrlValidator.isValid does not properly validate *.travel
domains
* [VALIDATOR-292] - @localhost and @localhost.localdomain email addresses
aren't correctly detected as valid
* [VALIDATOR-293] - Email validation fails with dash or hyphen at end of
local address
IMPROVEMENTS OVER PREVIOUS RELEASE
===================================
* [VALIDATOR-188] - Extend ISBN validator to support smooth transition to
ISBN-13 / EAN-13 standard
* [VALIDATOR-191] - Remove the dependency on Jakarta ORO (move to JDK 1.4
regular expression support)
* [VALIDATOR-192] - Adding ISBNValidator to GenericValidator
* [VALIDATOR-193] - Removing ORO dep. from GenericValidator
* [VALIDATOR-203] - Refactor UrlValidator - especially the line 370-ish.
* [VALIDATOR-211] - Upgrade to Digester 1.8
* [VALIDATOR-213] - Factor out Check Digit logic into separate
implementations
* [VALIDATOR-214] - New Regular Expression validator using JDK 1.4's Regex
* [VALIDATOR-215] - New generic CodeValidator that validates format, length
and Check Digit for a code
* [VALIDATOR-224] - validatorUtilities.js - replace colon characters in the
function name (JSF/Shale)
* [VALIDATOR-226] - Null-Stream input to ValidatorResources leads to
MalformedURLExceptions
* [VALIDATOR-232] - Add script attribute to control script generation
* [VALIDATOR-233] - Switch to using Version 0.4.3 of the Dojo Compressor
from the maven repo
* [VALIDATOR-234] - Create 1.4 DTD
* [VALIDATOR-240] - Support the 65 prefix for Discover Card
* [VALIDATOR-241] - New InetAdress Validator implementation
* [VALIDATOR-242] - Move EmailValidator to routines package
* [VALIDATOR-247] - Move CreditCardValidator to routines package and
refactor to use new CodeValidator
* [VALIDATOR-248] - Add an option to allow 'localhost' as a valid hostname
part in the URL
* [VALIDATOR-249] - Add Diners card validation to CreditCardValidator
* [VALIDATOR-250] - Banking CheckDigit implementations: ABA, CUSIP, IBAN,
ISIN and Sedol
* [VALIDATOR-251] - url with brackets is not validated thru URLvalidator
class.
* [VALIDATOR-252] - Performance improvement of DomainValidator by change
the regular expression
* [VALIDATOR-275] - EmailValidator.isValid(String) follows RFC822 but
violates RFC1034
* [VALIDATOR-288] - UrlValidator does not validate URL with simple domains
(eg: http://hostname )
* [VALIDATOR-300] - clirr Report - EmailValidator.isValidIpAddress() argument
type change
* [VALIDATOR-301] - CheckStyle and FindBug Issues - inner classes and key sets
DEPRECATIONS
============
* Most of the org.apache.commons.validator classes have been deprecated,
in favour of the new org.apache.commons.validator.routines classes.
OTHER NOTES
============
Users should be aware of the following potential issues with migration:
* The protected method validator.EmailValidator.isValidIpAddress() previously
exposed a Jakarta ORO class via its signature. The signature has been
modified to accept a a java.lang.String and is not therefore not compatible.
However, this class is deprecated and clients should use the equivalent
class in the validator.routines package.
* Invocations of the method GenericValidator.matchRegexp() should be inspected
for semantic differences between Jakarta ORO and Java regular expressions.
commons-validator-1.4.0-src/build-javascript.xml 100644 765 0 14664 11711227702 23023 0 ustar simonetripodi wheel 0 0
Dependencies: dependencies
for Validator 1.3.1 are unchanged since the 1.3.0 release.
N.B.Jakarta ORO
has now been marked as an optional dependency in the project.xml as it is only
required by the Email, URL and Regular Expression validations.
Add new routines package containing standard validations - first
step in the process of clearly separating standard validation
functions which can be used independantly, from the framework
aspect of Commons Validator. New validators added for Date, Time, Calendar, Byte, Short,
Integer, Long, Float, Double, BigInteger, BigDecimal,
Currency and Percent. Backwards Incompatible Changes Deprecated items; see the javadoc for details and replacements.null
.
GenericValidator
methods into reusable
objects. These include: CreditCardValidator, EmailValidator,
DateValidator, and UrlValidator.
position
attribute. Setting position to 0 is the equivalent
of an <arg0> element.
Arg.getResource()
CreditCardValidator.isValidPrefix()
Field.ARG_DEFAULT
Field.hDependencies
Field.hArg0 - Field.hArg3
Field.addArg0() - Field.addArg3()
Field.getArg0() - Field.getArg3()
Field.addVarParam()
Field.process()
Field.processMessageComponents()
Field.getDependencies()
Form.getFieldMap()
Form.process()
FormSet.addConstant()
FormSet.addConstantParam()
FormSet.getForm(Object)
FormSet.process()
GenericValidator.REGEXP_DELIM
GenericValidator.validateCreditCardLuhnCheck()
GenericValidator.validateCreditCardPrefixCheck()
GenericValidator.getDelimittedRegExp()
Validator.BEAN_KEY
Validator.VALIDATOR_ACTION_KEY
Validator.FIELD_KEY
Validator.VALIDATOR_KEY
Validator.LOCALE_KEY
Validator.hResources
Validator.addResource()
Validator.getResource()
ValidatorAction.process()
ValidatorAction.getDependencies()
ValidatorResources.put()
ValidatorResources.addConstant()
ValidatorResources.addConstantParam()
ValidatorResources.get()
ValidatorResources.processForms()
ValidatorResourcesInitializer
ValidatorResult.getValid()
ValidatorResults.empty()
ValidatorResults.get()
ValidatorResults.properties()
ValidatorUtil
A simple example of setting up and using the Validator.
* * This simple example shows all the steps needed to set up and use * the Validator. Note that in most cases, some kind of framework * would be wrapped around the Validator, such as is the case with * the Struts Validator Framework. However, should you wish to use * the Validator against raw Beans in a pure Java application, you * can see everything you need to know to get it working here. * * @version $Revision: 478334 $ $Date: 2006-11-22 22:31:54 +0100 (Wed, 22 Nov 2006) $ */ public class ValidateExample extends Object { /** * We need a resource bundle to get our field names and errors messages * from. Note that this is not strictly required to make the Validator * work, but is a good coding practice. */ private static ResourceBundle apps = ResourceBundle.getBundle( "org.apache.commons.validator.example.applicationResources"); /** * This is the main method that will be called to initialize the Validator, create some sample beans, and * run the Validator against them. */ public static void main(String[] args) throws ValidatorException, IOException, SAXException { InputStream in = null; ValidatorResources resources = null; try { // Create a new instance of a ValidatorResource, then get a stream // handle on the XML file with the actions in it, and initialize the // resources from it. This would normally be done by a servlet // run during JSP initialization or some other application-startup // routine. in = ValidateExample.class.getResourceAsStream("validator-example.xml"); resources = new ValidatorResources(in); } finally { // Make sure we close the input stream. if (in != null) { in.close(); } } // Create a test bean to validate against. ValidateBean bean = new ValidateBean(); // Create a validator with the ValidateBean actions for the bean // we're interested in. Validator validator = new Validator(resources, "ValidateBean"); // Tell the validator which bean to validate against. validator.setParameter(Validator.BEAN_PARAM, bean); ValidatorResults results = null; // Run the validation actions against the bean. Since all of the properties // are null, we expect them all to error out except for street2, which has // no validations (it's an optional property) results = validator.validate(); printResults(bean, results, resources); // Now set all the required properties, but make the age a non-integer. // You'll notice that age will pass the required test, but fail the int // test. bean.setLastName("Tester"); bean.setFirstName("John"); bean.setStreet1("1 Test Street"); bean.setCity("Testville"); bean.setState("TE"); bean.setPostalCode("12345"); bean.setAge("Too Old"); results = validator.validate(); printResults(bean, results, resources); // Now only report failed fields validator.setOnlyReturnErrors(true); results = validator.validate(); printResults(bean, results, resources); // Now everything should pass. validator.setOnlyReturnErrors(false); bean.setAge("123"); results = validator.validate(); printResults(bean, results, resources); } /** * Dumps out the Bean in question and the results of validating it. */ public static void printResults( ValidateBean bean, ValidatorResults results, ValidatorResources resources) { boolean success = true; // Start by getting the form for the current locale and Bean. Form form = resources.getForm(Locale.getDefault(), "ValidateBean"); System.out.println("\n\nValidating:"); System.out.println(bean); // Iterate over each of the properties of the Bean which had messages. Iterator propertyNames = results.getPropertyNames().iterator(); while (propertyNames.hasNext()) { String propertyName = (String) propertyNames.next(); // Get the Field associated with that property in the Form Field field = form.getField(propertyName); // Look up the formatted name of the field from the Field arg0 String prettyFieldName = apps.getString(field.getArg(0).getKey()); // Get the result of validating the property. ValidatorResult result = results.getValidatorResult(propertyName); // Get all the actions run against the property, and iterate over their names. Map actionMap = result.getActionMap(); Iterator keys = actionMap.keySet().iterator(); while (keys.hasNext()) { String actName = (String) keys.next(); // Get the Action for that name. ValidatorAction action = resources.getValidatorAction(actName); // If the result is valid, print PASSED, otherwise print FAILED System.out.println( propertyName + "[" + actName + "] (" + (result.isValid(actName) ? "PASSED" : "FAILED") + ")"); //If the result failed, format the Action's message against the formatted field name if (!result.isValid(actName)) { success = false; String message = apps.getString(action.getMsg()); Object[] args = { prettyFieldName }; System.out.println( " Error message will be: " + MessageFormat.format(message, args)); } } } if (success) { System.out.println("FORM VALIDATION PASSED"); } else { System.out.println("FORM VALIDATION FAILED"); } } } ././@LongLink 100644 0 0 155 11711231552 10252 L ustar 0 0 commons-validator-1.4.0-src/src/example/org/apache/commons/validator/example/applicationResources.properties commons-validator-1.4.0-src/src/example/org/apache/commons/validator/example/applicationResources.pr100644 765 0 2336 11711227702 35075 0 ustar simonetripodi wheel 0 0 # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # The error messages for the Validation Actions errors.required=The {0} field is required. errors.int=The {0} field is not an integer. # The formatted names of the properties nameForm.age.displayname=Age nameForm.lastname.displayname=Last Name nameForm.firstname.displayname=First Name nameForm.city.displayname=City nameForm.state.displayname=State nameForm.postalCode.displayname=Postal Code nameForm.street1.displayname=Street Address commons-validator-1.4.0-src/src/example/org/apache/commons/validator/example/validator-example.xml 100644 765 0 4777 11711227702 34507 0 ustar simonetripodi wheel 0 0 The validator javascript package provides a series of functions to
validate form input data
.
Field
Type |
validate Byte |
validate CreditCard |
validate Date |
validate |
validate Float |
validate FloatRange |
validate IntRange |
validate Integer |
validate Mask |
validate MaxRange |
validate MinRange |
validate Required |
validate Short |
checkbox |
![]() |
||||||||||||
file | ![]() |
![]() |
|||||||||||
hidden 2 | ![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
|
password | ![]() |
![]() |
![]() |
||||||||||
radio | ![]() |
![]() |
![]() |
![]() |
![]() |
||||||||
select-multiple | ![]() |
||||||||||||
select-one | ![]() |
![]() |
![]() |
![]() |
![]() |
||||||||
text | ![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
textarea | ![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Notes
1) | Since few browser support the 'accept' attribute for file upload input fields, a mask can be used to validate the uploaded file extension. |
|
---|---|---|
2) | Hidden fields can be used with complicated HTML interface. like cascading inter-dependent menus. The menus themselves don't represent real data fields, but are used with javascript to set the value of a hidden field. |
commons-validator-1.4.0-src/src/javascript/org/apache/commons/validator/javascript/validateByte.js 100644 765 0 5771 11711227702 34543 0 ustar simonetripodi wheel 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /*$RCSfile: validateByte.js,v $ $Rev: 478676 $ $Date: 2006-11-23 22:35:44 +0100 (Thu, 23 Nov 2006) $ */ /** * Check to see if fields are a valid byte. * Fields are not checked if they are disabled. * @param form The form validation is taking place on. */ function validateByte(form) { var bValid = true; var focusField = null; var i = 0; var fields = new Array(); var oByte = eval('new ' + jcv_retrieveFormName(form) + '_ByteValidations()'); for (var x in oByte) { if (!jcv_verifyArrayElement(x, oByte[x])) { continue; } var field = form[oByte[x][0]]; if (!jcv_isFieldPresent(field)) { continue; } if ((field.type == 'hidden' || field.type == 'text' || field.type == 'textarea' || field.type == 'select-one' || field.type == 'radio')) { var value = ''; // get field's value if (field.type == "select-one") { var si = field.selectedIndex; if (si >= 0) { value = field.options[si].value; } } else { value = field.value; } if (value.length > 0) { if (!jcv_isDecimalDigits(value)) { bValid = false; if (i == 0) { focusField = field; } fields[i++] = oByte[x][1]; } else { var iValue = parseInt(value, 10); if (isNaN(iValue) || !(iValue >= -128 && iValue <= 127)) { if (i == 0) { focusField = field; } fields[i++] = oByte[x][1]; bValid = false; } } } } } if (fields.length > 0) { jcv_handleErrors(fields, focusField); } return bValid; } ././@LongLink 100644 0 0 151 11711231552 10246 L ustar 0 0 commons-validator-1.4.0-src/src/javascript/org/apache/commons/validator/javascript/validateCreditCard.js commons-validator-1.4.0-src/src/javascript/org/apache/commons/validator/javascript/validateCreditCar100644 765 0 6604 11711227702 35061 0 ustar simonetripodi wheel 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /*$RCSfile: validateCreditCard.js,v $ $Rev: 478676 $ $Date: 2006-11-23 22:35:44 +0100 (Thu, 23 Nov 2006) $ */ /** * Check to see if fields are a valid creditcard number based on Luhn checksum. * Fields are not checked if they are disabled. * @param form The form validation is taking place on. */ function validateCreditCard(form) { var bValid = true; var focusField = null; var i = 0; var fields = new Array(); var oCreditCard = eval('new ' + jcv_retrieveFormName(form) + '_creditCard()'); for (var x in oCreditCard) { if (!jcv_verifyArrayElement(x, oCreditCard[x])) { continue; } var field = form[oCreditCard[x][0]]; if (!jcv_isFieldPresent(field)) { continue; } if ((field.type == 'text' || field.type == 'textarea') && (field.value.length > 0)) { if (!jcv_luhnCheck(field.value)) { if (i == 0) { focusField = field; } fields[i++] = oCreditCard[x][1]; bValid = false; } } } if (fields.length > 0) { jcv_handleErrors(fields, focusField); } return bValid; } /** * Checks whether a given credit card number has a valid Luhn checksum. * This allows you to spot most randomly made-up or garbled credit card numbers immediately. * Reference: http://www.speech.cs.cmu.edu/~sburke/pub/luhn_lib.html */ function jcv_luhnCheck(cardNumber) { if (jcv_isLuhnNum(cardNumber)) { var no_digit = cardNumber.length; var oddoeven = no_digit & 1; var sum = 0; for (var count = 0; count < no_digit; count++) { var digit = parseInt(cardNumber.charAt(count)); if (!((count & 1) ^ oddoeven)) { digit *= 2; if (digit > 9) digit -= 9; }; sum += digit; }; if (sum == 0) return false; if (sum % 10 == 0) return true; }; return false; } function jcv_isLuhnNum(argvalue) { argvalue = argvalue.toString(); if (argvalue.length == 0) { return false; } for (var n = 0; n < argvalue.length; n++) { if ((argvalue.substring(n, n+1) < "0") || (argvalue.substring(n,n+1) > "9")) { return false; } } return true; } commons-validator-1.4.0-src/src/javascript/org/apache/commons/validator/javascript/validateDate.js 100644 765 0 23262 11711227702 34530 0 ustar simonetripodi wheel 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /*$RCSfile: validateDate.js,v $ $Rev: 478676 $ $Date: 2006-11-23 22:35:44 +0100 (Thu, 23 Nov 2006) $ */ /** * Check to see if fields are a valid date. * Fields are not checked if they are disabled. * @param form The form validation is taking place on. */ function validateDate(form) { var bValid = true; var focusField = null; var i = 0; var fields = new Array(); var oDate = eval('new ' + jcv_retrieveFormName(form) + '_DateValidations()'); for (var x in oDate) { if (!jcv_verifyArrayElement(x, oDate[x])) { continue; } var field = form[oDate[x][0]]; if (!jcv_isFieldPresent(field)) { continue; } var value = field.value; var isStrict = true; var datePattern = oDate[x][2]("datePatternStrict"); // try loose pattern if (datePattern == null) { datePattern = oDate[x][2]("datePattern"); isStrict = false; } if ((field.type == 'hidden' || field.type == 'text' || field.type == 'textarea') && (value.length > 0) && (datePattern.length > 0)) { var MONTH = "MM"; var DAY = "dd"; var YEAR = "yyyy"; var orderMonth = datePattern.indexOf(MONTH); var orderDay = datePattern.indexOf(DAY); var orderYear = datePattern.indexOf(YEAR); if ((orderDay < orderYear && orderDay > orderMonth)) { var iDelim1 = orderMonth + MONTH.length; var iDelim2 = orderDay + DAY.length; var delim1 = datePattern.substring(iDelim1, iDelim1 + 1); var delim2 = datePattern.substring(iDelim2, iDelim2 + 1); if (iDelim1 == orderDay && iDelim2 == orderYear) { dateRegexp = isStrict ? new RegExp("^(\\d{2})(\\d{2})(\\d{4})$") : new RegExp("^(\\d{1,2})(\\d{1,2})(\\d{4})$"); } else if (iDelim1 == orderDay) { dateRegexp = isStrict ? new RegExp("^(\\d{2})(\\d{2})[" + delim2 + "](\\d{4})$") : new RegExp("^(\\d{1,2})(\\d{1,2})[" + delim2 + "](\\d{4})$"); } else if (iDelim2 == orderYear) { dateRegexp = isStrict ? new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})(\\d{4})$") : new RegExp("^(\\d{1,2})[" + delim1 + "](\\d{1,2})(\\d{4})$"); } else { dateRegexp = isStrict ? new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{4})$") : new RegExp("^(\\d{1,2})[" + delim1 + "](\\d{1,2})[" + delim2 + "](\\d{4})$"); } var matched = dateRegexp.exec(value); if(matched != null) { if (!jcv_isValidDate(matched[2], matched[1], matched[3])) { if (i == 0) { focusField = field; } fields[i++] = oDate[x][1]; bValid = false; } } else { if (i == 0) { focusField = field; } fields[i++] = oDate[x][1]; bValid = false; } } else if ((orderMonth < orderYear && orderMonth > orderDay)) { var iDelim1 = orderDay + DAY.length; var iDelim2 = orderMonth + MONTH.length; var delim1 = datePattern.substring(iDelim1, iDelim1 + 1); var delim2 = datePattern.substring(iDelim2, iDelim2 + 1); if (iDelim1 == orderMonth && iDelim2 == orderYear) { dateRegexp = isStrict ? new RegExp("^(\\d{2})(\\d{2})(\\d{4})$") : new RegExp("^(\\d{1,2})(\\d{1,2})(\\d{4})$"); } else if (iDelim1 == orderMonth) { dateRegexp = isStrict ? new RegExp("^(\\d{2})(\\d{2})[" + delim2 + "](\\d{4})$") : new RegExp("^(\\d{1,2})(\\d{1,2})[" + delim2 + "](\\d{4})$"); } else if (iDelim2 == orderYear) { dateRegexp = isStrict ? new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})(\\d{4})$") : new RegExp("^(\\d{1,2})[" + delim1 + "](\\d{1,2})(\\d{4})$"); } else { dateRegexp = isStrict ? new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{4})$") : new RegExp("^(\\d{1,2})[" + delim1 + "](\\d{1,2})[" + delim2 + "](\\d{4})$"); } var matched = dateRegexp.exec(value); if(matched != null) { if (!jcv_isValidDate(matched[1], matched[2], matched[3])) { if (i == 0) { focusField = field; } fields[i++] = oDate[x][1]; bValid = false; } } else { if (i == 0) { focusField = field; } fields[i++] = oDate[x][1]; bValid = false; } } else if ((orderMonth > orderYear && orderMonth < orderDay)) { var iDelim1 = orderYear + YEAR.length; var iDelim2 = orderMonth + MONTH.length; var delim1 = datePattern.substring(iDelim1, iDelim1 + 1); var delim2 = datePattern.substring(iDelim2, iDelim2 + 1); if (iDelim1 == orderMonth && iDelim2 == orderDay) { dateRegexp = isStrict ? new RegExp("^(\\d{4})(\\d{2})(\\d{2})$") : new RegExp("^(\\d{4})(\\d{1,2})(\\d{1,2})$"); } else if (iDelim1 == orderMonth) { dateRegexp = isStrict ? new RegExp("^(\\d{4})(\\d{2})[" + delim2 + "](\\d{2})$") : new RegExp("^(\\d{4})(\\d{1,2})[" + delim2 + "](\\d{1,2})$"); } else if (iDelim2 == orderDay) { dateRegexp = isStrict ? new RegExp("^(\\d{4})[" + delim1 + "](\\d{2})(\\d{2})$") : new RegExp("^(\\d{4})[" + delim1 + "](\\d{1,2})(\\d{1,2})$"); } else { dateRegexp = isStrict ? new RegExp("^(\\d{4})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{2})$") : new RegExp("^(\\d{4})[" + delim1 + "](\\d{1,2})[" + delim2 + "](\\d{1,2})$"); } var matched = dateRegexp.exec(value); if(matched != null) { if (!jcv_isValidDate(matched[3], matched[2], matched[1])) { if (i == 0) { focusField = field; } fields[i++] = oDate[x][1]; bValid = false; } } else { if (i == 0) { focusField = field; } fields[i++] = oDate[x][1]; bValid = false; } } else { if (i == 0) { focusField = field; } fields[i++] = oDate[x][1]; bValid = false; } } } if (fields.length > 0) { jcv_handleErrors(fields, focusField); } return bValid; } function jcv_isValidDate(day, month, year) { if (month < 1 || month > 12) { return false; } if (day < 1 || day > 31) { return false; } if ((month == 4 || month == 6 || month == 9 || month == 11) && (day == 31)) { return false; } if (month == 2) { var leap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); if (day>29 || (day == 29 && !leap)) { return false; } } return true; } commons-validator-1.4.0-src/src/javascript/org/apache/commons/validator/javascript/validateEmail.js 100644 765 0 10345 11711227702 34700 0 ustar simonetripodi wheel 0 0 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /*$RCSfile: validateEmail.js,v $ $Rev: 478676 $ $Date: 2006-11-23 22:35:44 +0100 (Thu, 23 Nov 2006) $ */ /** * Check to see if fields are a valid email address. * Fields are not checked if they are disabled. * @param form The form validation is taking place on. */ function validateEmail(form) { var bValid = true; var focusField = null; var i = 0; var fields = new Array(); var oEmail = eval('new ' + jcv_retrieveFormName(form) + '_email()'); for (var x in oEmail) { if (!jcv_verifyArrayElement(x, oEmail[x])) { continue; } var field = form[oEmail[x][0]]; if (!jcv_isFieldPresent(field)) { continue; } if ((field.type == 'hidden' || field.type == 'text' || field.type == 'textarea') && (field.value.length > 0)) { if (!jcv_checkEmail(field.value)) { if (i == 0) { focusField = field; } fields[i++] = oEmail[x][1]; bValid = false; } } } if (fields.length > 0) { jcv_handleErrors(fields, focusField); } return bValid; } /** * Reference: Sandeep V. Tamhankar (stamhankar@hotmail.com), * http://javascript.internet.com */ function jcv_checkEmail(emailStr) { if (emailStr.length == 0) { return true; } // TLD checking turned off by default var checkTLD=0; var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/; var emailPat=/^(.+)@(.+)$/; var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]"; var validChars="\[^\\s" + specialChars + "\]"; var quotedUser="(\"[^\"]*\")"; var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/; var atom=validChars + '+'; var word="(" + atom + "|" + quotedUser + ")"; var userPat=new RegExp("^" + word + "(\\." + word + ")*$"); var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$"); var matchArray=emailStr.match(emailPat); if (matchArray==null) { return false; } var user=matchArray[1]; var domain=matchArray[2]; for (i=0; i