Created
September 15, 2013 07:43
-
-
Save frayhan32/6568726 to your computer and use it in GitHub Desktop.
js_captcha
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//*************************************************************// | |
//***************************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