SelfServiceValidators.js revision e26e5073e1266868172d72453c97f413fe2fb603
2N/A/**
2N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2N/A *
2N/A * Copyright (c) 2011-2012 ForgeRock AS. All rights reserved.
2N/A *
2N/A * The contents of this file are subject to the terms
2N/A * of the Common Development and Distribution License
2N/A * (the License). You may not use this file except in
2N/A * compliance with the License.
2N/A *
2N/A * You can obtain a copy of the License at
2N/A * http://forgerock.org/license/CDDLv1.0.html
2N/A * See the License for the specific language governing
2N/A * permission and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL
2N/A * Header Notice in each file and include the License file
2N/A * at http://forgerock.org/license/CDDLv1.0.html
2N/A * If applicable, add the following below the CDDL Header,
2N/A * with the fields enclosed by brackets [] replaced by
2N/A * your own identifying information:
2N/A * "Portions Copyrighted [year] [name of copyright owner]"
2N/A */
2N/A
2N/A/*global define */
2N/A
2N/Adefine("config/validators/SelfServiceValidators", [
2N/A "jquery",
2N/A "UserDelegate"
2N/A], function($, userDelegate) {
2N/A var obj = {
2N/A "required_long": {
2N/A "name": "Not empty number",
2N/A "dependencies": [
2N/A ],
2N/A "validator": function(el, input, callback) {
2N/A var v = $(input).val();
2N/A if(v === "") {
2N/A callback($.t("common.form.validation.required"));
2N/A return;
2N/A }
2N/A if(!v.match(/^([0-9]+)$/)) {
2N/A callback($.t("common.form.validation.shouldBeLong"));
2N/A return;
2N/A }
2N/A callback();
2N/A }
2N/A },
2N/A "long": {
2N/A "name": "Number",
2N/A "dependencies": [
2N/A ],
2N/A "validator": function(el, input, callback) {
2N/A var v = $(input).val();
2N/A if(v !== "" && !v.match(/^([0-9]+)$/)) {
2N/A callback($.t("common.form.validation.shouldBeLong"));
2N/A return;
2N/A }
2N/A callback();
2N/A }
2N/A },
2N/A "required_formattedDate": {
2N/A "name": "Not empty, formatted date",
2N/A "dependencies": [
2N/A "org/forgerock/commons/ui/common/util/DateUtil"
2N/A ],
2N/A "validator": function(el, input, callback, dateUtil) {
2N/A var valueToReplace, date, v = $(input).val(), dateFormat = $(input).parent().find('[name=dateFormat]').val();
2N/A if(v === "") {
2N/A callback($.t("common.form.validation.required"));
2N/A return;
2N/A }
2N/A if(!dateUtil.isDateStringValid(v, dateFormat)) {
2N/A callback($.t("common.form.validation.wrongDateFormat") + " (" + dateFormat + ")");
2N/A return;
2N/A } else {
2N/A date = dateUtil.parseDateString(v, dateFormat);
2N/A valueToReplace = dateUtil.formatDate(date,dateFormat);
2N/A if (dateUtil.isDateStringValid(valueToReplace, dateFormat)) {
2N/A $(input).val(valueToReplace);
2N/A } else {
2N/A callback($.t("common.form.validation.wrongDateFormat") + " (" + dateFormat + ")");
2N/A return;
2N/A }
2N/A }
2N/A callback();
2N/A }
2N/A },
2N/A "formattedDate": {
2N/A "name": "Not empty, formatted date",
2N/A "dependencies": [
2N/A "org/forgerock/commons/ui/common/util/DateUtil"
2N/A ],
2N/A "validator": function(el, input, callback, dateUtil) {
2N/A var valueToReplace, date, v = $(input).val(), dateFormat = $(input).parent().find('[name=dateFormat]').val();
2N/A if(v !== ""){
2N/A if (!dateUtil.isDateStringValid(v, dateFormat)) {
2N/A callback($.t("common.form.validation.wrongDateFormat") + " (" + dateFormat + ")");
2N/A return;
2N/A } else {
2N/A date = dateUtil.parseDateString(v, dateFormat);
2N/A valueToReplace = dateUtil.formatDate(date,dateFormat);
2N/A if (dateUtil.isDateStringValid(valueToReplace, dateFormat)) {
2N/A $(input).val(valueToReplace);
2N/A } else {
2N/A callback($.t("common.form.validation.wrongDateFormat") + " (" + dateFormat + ")");
2N/A return;
2N/A }
2N/A }
2N/A }
2N/A callback();
2N/A }
2N/A },"required_max255": {
2N/A "name": "Not empty and no more than 256 chars",
2N/A "dependencies": [
2N/A ],
2N/A "validator": function(el, input, callback) {
2N/A var v = $(input).val();
2N/A if(v === "") {
2N/A callback($.t("common.form.validation.required"));
2N/A return;
2N/A }
2N/A if(v.length > 255) {
2N/A callback($.t("common.form.validation.shouldBeNotMoreThen256"));
2N/A return;
2N/A }
2N/A callback();
2N/A }
2N/A }
2N/A };
2N/A
2N/A return obj;
2N/A});
2N/A