开发者

Error with regex in jquery

开发者 https://www.devze.com 2023-04-09 15:31 出处:网络
I want to validate my textbox on keypress event. As I am newbie with jquery, I searched on google and found one jquery plugin named \'limitkeypress\'.

I want to validate my textbox on keypress event. As I am newbie with jquery, I searched on google and found one jquery plugin named 'limitkeypress'.

This is my code:

$(document).ready(function() {
    $("#title").limitkeypress({ rexp: /^[A-Za-z]*$/ }); 
});

Plugin library is:

http://brianjaeger.com/process.php

It's giving me the following error

$("#title").limitkeypress is not a function

When I checked the library on jsfiddle it shows me dozens of errors. Is there any other validation library or plugin?

EDIT Thanks everyone for your valuable comment. Finally I got the solution. Though I was including file correctly. but don't know Y it was not working. I wrote jQuery.noConflict(); and all the problem is solved. What exactly it work. Please let me know, though I read but doubt still I have doubt.开发者_开发知识库


regexp is ok: 'buGaGa'.match(/^[A-Za-z]*$/);
$("#title").limitkeypress is not a function probably you forget to inlude library or wrong path.
Check it in Firebug( Net -> All ) lib must be highlight in black, not red.


Made a demo: http://jsfiddle.net/tTASy/ plugin seems to work fine.

Check your path to the script. if you paste a link to your page we could help you more specifically.


You can do this in jQuery like this without the plugin..

$("#your_textbox").keypress(function() {
  var length = this.value.length;
  if(length >= MIN && length <= MAX) {
    $("#your_submit").removeAttr("disabled");
    $("#your_validation_div").hide();
  } else {
    $("#your_submit").attr("disabled", "disabled");
    $("#your_validation_div").show();
  }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消