jQuery Validator: Twitter username validator

Aug 7, 2012 javascript jquery
This post is more than 18 months old. Since technology changes too rapidly, this content may be out of date (but that's not always the case). Please remember to verify any technical or programming information with the current release.

If you use the jQuery Validation plugin, and of course, you follow an amazing PHP Programmer and now have twitter boxes on all your forms, you might need to validate it some day. I wrote this method for it.

jQuery.validator.addMethod("twitterhandle", 
  function(value) {
    if(value == "") return true;
    var pattern = /^\w{1,32}$/;
    var result = pattern.test(value);
    return result;
  }, 
  "Twitter handle only - no spaces, @, and not a URL."
);
Go to All Posts