Custom tweet button with javascript

I was following the topic Build Your Own Tweet Button on

They explicitly say

JavaScript Interfaces for Twitter are not available for custom Tweet Buttons.

But we can have a custom tweet button (or link) and still have the Twitter javascript  API (web intents).

All you have to do is to include the javascript file for the Twitter API:

<script src=""></script>

Your custom button (link in this example):

<a href="">Tweet</a>

This is the trick, instead of the link pointing to

your link should point to

This way you still be able to use Twitter API. The following code shows how you can get

the tweet event:'tweet', function (event) {
  // Do something there

Check the online demo


jQuery to prevent repeat myself for a long validation form

It’s quite frustrating when we spend a some time doing a jsFiddle and preparing an answer for Stack Overflow question and see the answer being removed by its user!

I’ve decided at least post it here, so that it wouldn’t be a total waste of my time.

The question was about how to reuse javascript code to perform validation of the user input.

Demo on jsFiddle

HTML code:

<input type="text" id="txtEmail"/>

<input type="button" id="btnSubmit" value="Submit" />

Javascript code:

var myValidations = function () {

  var isValidEmail = function(email){
    if (!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email)){
      return false;
      return true;

  return {
    isValidEmail: isValidEmail


  $('#btnSubmit').on('click', function() {
      alert('Email is valid!');
      alert('Email is not valid!');


The code above uses the Revealing Module Pattern to create a namespace for validations.
On myValidations we can add other functions to validate any user input.
In this example I have an email validation function that I can call from anywhere by passing the user input.