Skip to content

Instantly share code, notes, and snippets.

@frayhan32
Created September 15, 2013 07:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frayhan32/6568726 to your computer and use it in GitHub Desktop.
Save frayhan32/6568726 to your computer and use it in GitHub Desktop.
js_captcha
//*************************************************************//
//***************************JS CAPTCHA************************//
//*************************************************************//
//*************************************************************//
//*****************Please Read Carefully Before Using**********//
//*************************************************************//
//This my way when dealing with captcha
//I use help of Jquery so you should include jquery at first
//Depedency code to js_rand_it i make it before
//Visit this link if you havent seen
//https://gist.github.com/frayhan32/6568683
//Text captcha needs 3 arguments
/*length means the length of value to be returned*/
/*elem means Element to be appended for captcha visualization*/
/*elemhid means Hidden Element to be set its value for server side purpose*/
function textCaptcha(length,elem,elemhid){
var list="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var result="";
//iterate each of list until length we specified and store to result
for(var i=0;i<=length;i++){
result+=list.charAt(getRandomInt(0,list.length-1));
}
elem.append(result);
elemhid.attr('value',result);
}
//*******************TEST HIM*******************//
textCaptcha(6,$('#b'),$('#a'))
//**********************************************//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment