minpatternsmatch not a method not found

23 views
Skip to first unread message

Jason Durham

unread,
May 26, 2013, 6:22:53 PM5/26/13
to valida...@googlegroups.com
I have the following rule setup in my User config file for validating a password:

<rule type="minPatternsMatch" contexts="REGISTER,ADMIN_USER_ACCOUNT_UPDATE" failureMessage="The Password must contain at least one uppercase letter, one lowercase letter and one digit.">
<param name="minMatches" value="3" />
<param name="pattern_lowerCaseLetter" value="[a-z]" />
<param name="pattern_upperCaseLetter" value="[A-Z]" />
<param name="pattern_digit" value="[\d]" />
</rule>

This results in the following JSON to be sent to the client:

password
{
  • minpatternsmatch
    {
    • pattern_upperCaseLetter"[A-Z]",
    • pattern_digit"[\d]",
    • pattern_lowerCaseLetter"[a-z]",
    • minMatches3
    },
  • ...

I don't see this method in jQuery.validate.js, nor does it exist in $.validator at runtime.  Could I have something misconfigured that is preventing this method (and perhaps "equalto") from being added to the $.validator before client side validation runs?  If not, I don't see how others are using these types of rules on the client.

Thanks,
Jason

Jason Durham

unread,
May 26, 2013, 7:31:16 PM5/26/13
to valida...@googlegroups.com
After looking at ClientRuleScripter_MinPatternsMatch.cfc and checking my browser's debugger tool, I see that an html snippet is being returned when the page loads containing a <script> tag with the methods I've been having problems with.  /shrug

<script type="text/javascript"> /*<![CDATA[*/ jQuery(function ($) { $.validator.addMethod("nohtml", function (v, e, o) { var m = v.search("</?\\w+((\\s+\\w+(\\s*=\\s*(?:\\\".*?\\\"|'.*?'|[^'\\\">\\s]+))?)+\\s*|\\s*)/?>"); return m === -1; }, $.format("value cannot contain any HTML tags.")); $.validator.addMethod("regex", function (v, e, p) { if (v === '') { return true }; return v.match(p); }, $.format("The value entered does not match the specified pattern ({0})")); $.validator.addMethod("equalto", function (v, e, p) { console.log(e); var $parentForm = $(e).closest("form"); var $compareto = $(p, $parentForm); var target = $compareto.unbind(".validate-equalTo").bind("blur.validate-equalTo", function () { $(e).valid(); }); return v == target.getValue(); }, $.format("The value cannot not contain the value of another property.")); $.validator.addMethod("true", function (v, e, o) { if (v === '') { return true; } var re = /^([1-9]|true|yes)$/i; return re.test(v); }, $.format("The value entered must be a true boolean.")); $.validator.addMethod("time", function (v, e, p) { return this.optional(e) || /^([01][0-9])|(2[0123]):([0-5])([0-9])$/.test(v); }, $.format("The value must be a valid time.")); $.validator.addMethod("notregex", function (v, e, p) { if (v === '') { return true }; return !v.match(p); }, $.format("The value entered does not match the specified pattern ({0})")); $.validator.addMethod("boolean", function (v, e, o) { if (v === '') { return true; } var re = /^((-){0,1}[0-9]{1,}(\.([0-9]{1,})){0,1}|true|false|yes|no)$/i; return re.test(v); }, $.format("The value entered must be a boolean")); $.validator.addMethod("minpatternsmatch", function (v, e, o) { var minMatches = 1; var complexity = 0; if (!v.length) { return true; } if (o.minMatches) { minMatches = o.minMatches; } var re = /^pattern_/i; for (var key in o) { if (re.test(key) && v.match(o[key])) { complexity++; if (complexity === minMatches) { return true; } } } return complexity >= minMatches; }, $.format("Value did not match the pattern requirements.")); $.validator.addMethod("pastdate", function (v, e, o) { if (v === '') { return true; } var dBefore = new Date(); dBefore = new Date(dBefore.toDateString()); var dValue = new Date(v); var ok = !/Invalid|NaN/.test(dValue); if (o.before) { dBefore = new Date(o.before); } if (ok) { ok = dBefore > dValue } return ok; }, $.format("The date entered must be in the past.")); $.validator.addMethod("inlist", function (v, e, o) { if (v === '') { return true; } var delim = o.delim ? o.delim : ","; var lst = o.list.split(delim); var ok = false; $.each(lst, function (i, el) { if (v.toLowerCase() == el.toLowerCase()) { ok = true; return false; } }); return ok; }, $.format("value was not found in list.")); $.validator.addMethod("notinlist", function (v, e, o) { var delim = o.delim ? o.delim : ","; var lst = o.list.split(delim); var ok = true; $.each(lst, function (i, el) { if (v.toLowerCase() === el.toLowerCase()) { ok = false; return false; } }); return ok; }, $.format("Value was found in list.")); $.validator.addMethod("doesnotcontainotherproperties", function (v, e, o) { var ok = true; var $form = $(e).closest("form"); $(o).each(function () { var propertyValue = $(':input[name=' + this + ']', $form).getValue(); if (propertyValue.length) { if (propertyValue.search(",")) { propertyValue = propertyValue.split(","); } $(propertyValue).each(function () { var test = v.toString().toLowerCase().search(this.toString().toLowerCase()) === -1; if (!test) { ok = false; } }); } return ok; }); return ok; }, $.format("The value cannot not contain the value of another property.")); $.validator.addMethod("false", function (v, e, o) { if (v === '') { return true; } var re = /^(0|false|no)$/i; return re.test(v); }, $.format("The value entered must be a false boolean.")); $.validator.addMethod("daterange", function (v, e, o) { if (v === '') return true; var thedate = new Date(v); var ok = !/Invalid|NaN/.test(thedate); var start = new Date(); var end = new Date(); if (ok) { if (o.from) { start = new Date(o.from); } if (o.until) { var end = new Date(o.until); } if (start !== end) { ok = ((start <= thedate) && (thedate <= end)); } } return ok; }, $.format("The date entered must be in the range specified.")); $.validator.addMethod("futuredate", function (v, e, o) { if (v === '') { return true; } var dToday = new Date(); var dValue = new Date(v); if (o.after) { dToday = new Date(o.after); } return (dToday < dValue); }, $.format("The date entered must be in the future.")); }); /*]]>*/ </script>
Reply all
Reply to author
Forward
0 new messages