0

숫자와 문자가이 0000-00-0000A와 같이 필요합니다. 나는 프로젝트에서 일하고있다. 그래서 나는 쿠폰을 놓을 때 무작위 숫자와 문자가 내가있는 곳에있는 쿠폰 id에 나타날 것이지만, 모든 쿠폰에 대해 숫자와 문자가 다르다. 그리고 난 2 개월 코딩에 새로운 오전과 나는이 난수를 제외하고 괜찮아요 일을한다고 생각합니다. 내가하는 일의 예가 아래에있다.프로젝트에 숫자 및 문자 생성기가 필요합니다.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Untitled Document</title> 
<style> 
#coupon{ 
    width: 600px; 
    height:auto; 
    top:145px; 
    background: #FFFF95; 
    margin: 2px auto; 
    border: 1px solid #000000; 
    text-align: center; 
    -webkit-border-top-left-radius:06px; 
    -webkit-border-top-right-radius:06px; 
    -webkit-border-bottom-left-radius:06px; 
    -webkit-border-bottom-right-radius:06px; 
    -moz-border-radius-topleft:06px; 
    -moz-border-radius-bottomleft:06px; 
    -moz-border-radius-topright:06px; 
    -moz-border-radius-bottomright:06px; 
    border-top-left-radius:06px; 
    border-top-right-radius:06px; 
    border-bottom-left-radius:06px; 
    border-bottom-right-radius:06px; 
    /* additional features, can be omitted */ 
    border:2px outset #093; 
    padding:15px; 
    font-size:15px; 
    -moz-box-shadow: 0 0 15px #999; 
    -webkit-box-shadow: 0 0 15px #999; 
    box-shadow: 0 0 15px #999; 
} 


</style> 
</head> 

<body> 
<div id="coupon" class="coupon"> 
<p>This can be the coupn area where the cupon is place and the deal can be read then printed!</p> 
<div class="print-page" id="print-page"> 
    <p><a href=" #" onClick=" window.print()" >Print Deal</a></p> 
</div> 
<div class="coupon-id-number" id="coupon-id-number">0000-00-0000-A</div></div> 

</body> 
</html> 

누구든지 나를 도와 줄 수 있습니까? 당신은 같은 것을 할 것입니다 자바에서

+0

같은 기능을해야 할 수도 있습니다 서버 측 기술의 어떤 종류의 당신을 용도? – Thilo

+1

어떤 언어를 사용하고 싶습니까? 데이터베이스를 사용하여 쿠폰 번호를 저장하면 나중에 단일 용도로 사용할 수 있습니다. – TomDunning

+0

java and iquery really ... 나는 거의 모든 것에 익숙하지 않은데, 예, 나는 이드의 쿠폰을 저장하는 모든 시스템을 가지고 있습니다. Javascript가 선호됩니다. – Thedude420

답변

0

, 당신은

<script> 
function genRandom() { 
    var genNumber = function (length) { 
     return ~~(Math.random() * length); 
     }, 
     genChar = function() { 
     var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXZ', 
      index = genNumber(24); 

     return chars.slice(index, index + 1); 
     }, 
     arr = [genNumber(10000), genNumber(100), genNumber(10000), genChar()]; 
    return arr.join('-'); 
} 

document.getElementById('coupon-id-number').innerHTML = genRandom(); 
</script> 
1

: 자바 스크립트하여이 작업을 수행하려는 경우

Random random = new Random(); 
String couponCode = String.format("%04d-%02d-%04d-%s", random.nextInt(10000), random.nextInt(100), random.nextInt(10000), (char)(random.nextInt(26)+65)); 
+0

당신은이 서버 측을 데이터베이스에 삽입하고 동일한 코드가 이미 존재하지 않는다는 것을 테스트하기를 원합니다. 클라이언트 측에서 Ajax를 사용하여 서버로부터 새로운 쿠폰 코드를 가져옵니다. –

+0

랜덤 번호 이미 토큰이기 때문에 데이터베이스에서 추적해야합니다. – Oritm

+0

쿠폰 코드의 경우 SecureRandom 또는 UUID를 사용합니다. – Thilo

관련 문제