I'm sorry this might be duplicated post, but i really not understand how can i do this. In my system I need to generate a code(coupon) which are alphanumeric around 6 - 8 value, and if user key simply key in the code which is not under generated code(coupon) it will show error message.
i saw alot of ppl using, but i failed to applied this during import the import java.util.UUID;
String uniqueID = UUID.randomUUID().toString(); //UUID method
What i have done so far only can generate a random number ( not expected result)
Javascript
var keylist="abcdefghijklmnopqrstuvwxyz123456789";
var temp="";
function generatecoupon(plength){
temp = "";
for (i=0;i<plength;i++)
temp+=keylist.charAt(Math.floor(Math.random()*keylist.length));
return temp;
}
function populateform(enterlength){
document.mainfrm.COUPON.value=generatecoupon(enterlength);
}
html
<input type="button" value="Generate Coupon" onClick="populateform(this.form.thelength.value)">
<input type="hidden" name="thelength" size=3 value="6">
<input name="COUPON" type="text" id="COUPON" size="20" maxlength="20">
Need a guide in java code to generated random unique code and checked if the value key in if out of the generated value will show error message , Please any help would be appreciated