Search code examples
jqueryjquery-uinumbersnumericjquery-validation-engine

Number check and using pattern?


The point is, that during the jquery.validation.js $.validator.addMethod("pattern"... pattern for general are modified to:

"^(?:" + myPattern + ")$" on line 612 in the jquery.validation.js source and as this result the pattern check is invalid. Equal if I key in 10 10.0 or 10,0.

text:   "ok",
id:     "btn_ok",
name:   "btn_ok",
click:	function() {
  $("#dataset").validate({
  debug: true,
  rules: {
    myNumInput: {
		pattern: "((/^\d+)|(/^\d+\,\d*?))$"
    }
  },

  showErrors: function(errorMap, errorList) {
    var jsMsg = "";
      if (errorList.length > 0) {
          jsMsg = "<div id='msg' class='msg' style=''><div>Error: Value must be " + errorList[0].element.name.toUpperCase()  + " " +       
          errorList[0].message.toLowerCase() + "</div></div>";
		  $(".isReturn").html("<b>" + jsMsg + "</b>");
          errorList[0].element.style.border = "solid red 1px";
          errorList[0].element.focus();
      }
  }
});

Any idea?


Solution

  • solved!

    the point is, how key in patterns...

    instead of using this syntax:

    pattern: "((/^\d+)|(/^\d+\,\d*?))$"

    this one works...:

    pattern: /((^\d+)|(^\d+\,\d*?))$/

    the important part is the "-sign. dont use it. should be a part of the documentation.