Bitcoin Forum
November 26, 2020, 08:15:34 PM *
News: Bitcointalk Community Awards
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: [DONE] Paying .1 BTC for simple Javascript fix  (Read 769 times)
BitcoinMoxy
Full Member
***
Offline Offline

Activity: 120
Merit: 100


BitcoinMoxy.com


View Profile WWW
May 21, 2013, 09:11:42 AM
Last edit: May 29, 2013, 12:06:08 AM by BitcoinMoxy
 #1

Looking for a small enhancement to our QR code generator (Javascript) on BitcoinMoxy.com

I invite you to have a look at the related code in the .js scripts and the form at the beginning of the document body (index.html).

The generator works great so far and upon entering any value deviating from the valid character count in a Bitcoin address (25-34 chars), it defaults to a generic error msg in the QR code.

I want to extend this to show the same error qr-code whenever the user enters any non-alphanumeric characters (i.e. spaces, punctuation, etc.; valid input doesn't HAVE to be limited to BASE58, but would be really cool. [BTC addresses use BASE58 characters only]).

If there's anybody with some spare minutes to spend on this, you'll make my day!

Reply in the comments or PM me.

Payment: .1 BTC.


BitcoinMoxy.com - Your Gateway into the World of Bitcoin for Newcomers, Day Traders, Advertisers.
Service updates: https://bitcointalk.org/index.php?topic=254631.0
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
NLNico
Legendary
*
hacker
Offline Offline

Activity: 1876
Merit: 1264


DiceSites.com owner


View Profile WWW
May 21, 2013, 09:31:56 AM
Last edit: May 21, 2013, 09:50:24 AM by NLNico
 #2

In qrconf.jf

Add the following:
Code:
if(text.match(/[^123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+/g)) {
document.getElementById('qr').innerHTML = create_qrcode('Error!');
}
after:
Code:
replace(/^[\s\u3000]+|[\s\u3000]+$/g, '');
on a new line.

OR

I would personally prefer to just remove all the non bitcoin address characters from the input instead of showing an error. For that, replace:
Code:
replace(/^[\s\u3000]+|[\s\u3000]+$/g, '');
with:
Code:
replace(/[^123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+/g, '');


Bitcoin address for tip is in signature Wink

BitcoinMoxy
Full Member
***
Offline Offline

Activity: 120
Merit: 100


BitcoinMoxy.com


View Profile WWW
May 22, 2013, 06:47:48 PM
 #3

Thanks for the contribution, solution #1 looks perfectly good to me but it doesn't work the way I want it to work.
I've been trying the code, rewriting it a little, etc. but it keeps doing what it wants.
Sometimes it works, sometimes it doesn't. (Programming languages just don't come natural to me).

What I want it to do is this:

- create a QR code with a default error message in the QR as defined in var error whenever the input
      -is less than 25 characters in length
      -has any non-BASE58 characters in it

else, create the QR for a valid Bitcoin (or any altcoin address) using create_qrcode(text).

Make me a quote for payment along with the solution (but stay within reason, please).


Here's the code in qrconf.js after trying out different things (the original one is still up on the site):

Code:
var draw_qrcode = function(text, typeNumber, errorCorrectLevel) {
document.write(create_qrcode(text, typeNumber, errorCorrectLevel) );
};

var error = "Try Again!";
var text = document.forms[0].elements['msg'].value;

var create_qrcode = function(text, typeNumber, errorCorrectLevel, table) {

var qr = qrcode(typeNumber || 4, errorCorrectLevel || 'H');
qr.addData(text);
qr.make();

// return qr.createTableTag();
return qr.createImgTag();
};


var update_qrcode = function() {
var text = document.forms[0].elements['msg'].value;

if (text.length < 25) {
document.getElementById('qr').innerHTML = create_qrcode(error);
}

if(text.match(/[^123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+/g)) {
document.getElementById('qr').innerHTML = create_qrcode(error);
}

else {
document.getElementById('qr').innerHTML = create_qrcode(text);

};


};



I don't get why it doesn't work.. what am I doing wrong?

Thanks in advance


BitcoinMoxy.com - Your Gateway into the World of Bitcoin for Newcomers, Day Traders, Advertisers.
Service updates: https://bitcointalk.org/index.php?topic=254631.0
NLNico
Legendary
*
hacker
Offline Offline

Activity: 1876
Merit: 1264


DiceSites.com owner


View Profile WWW
May 23, 2013, 04:24:16 AM
 #4

Yeh I forget there was an "else". The problem: first it checks for length, if it's only 15 characters it will show error, but then it will go to the next "if" and if it has correct characters it will go to the "else" and show the QR code even though it's less than 25 characters.


You could combine this:
Code:
if (text.length < 25) {
document.getElementById('qr').innerHTML = create_qrcode(error);
}

if(text.match(/[^123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+/g)) {
document.getElementById('qr').innerHTML = create_qrcode(error);
}
to:
Code:
if (text.length < 25 || text.match(/[^123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+/g)) {
document.getElementById('qr').innerHTML = create_qrcode(error);
}

This should work, you can test it also here: http://jsfiddle.net/J325A/ (you can modify the "text" to invalid address then run again.)


BitcoinMoxy
Full Member
***
Offline Offline

Activity: 120
Merit: 100


BitcoinMoxy.com


View Profile WWW
May 24, 2013, 03:50:57 PM
 #5

Hold on. Let me have a look at this.




BitcoinMoxy.com - Your Gateway into the World of Bitcoin for Newcomers, Day Traders, Advertisers.
Service updates: https://bitcointalk.org/index.php?topic=254631.0
jezagee
Newbie
*
Offline Offline

Activity: 6
Merit: 0


View Profile
May 24, 2013, 05:10:34 PM
 #6

Gotta love QR!
BitcoinMoxy
Full Member
***
Offline Offline

Activity: 120
Merit: 100


BitcoinMoxy.com


View Profile WWW
May 29, 2013, 12:02:29 AM
 #7

Thank you very much.

Your input has been invaluable! Payment sent using your code.

 Cool

BitcoinMoxy.com



BitcoinMoxy.com - Your Gateway into the World of Bitcoin for Newcomers, Day Traders, Advertisers.
Service updates: https://bitcointalk.org/index.php?topic=254631.0
NLNico
Legendary
*
hacker
Offline Offline

Activity: 1876
Merit: 1264


DiceSites.com owner


View Profile WWW
May 29, 2013, 01:19:15 AM
 #8

Got the payment, thanks. Good luck with your website Smiley

kodo
Newbie
*
Offline Offline

Activity: 42
Merit: 0



View Profile
May 29, 2013, 01:22:21 AM
 #9

So your problems completly fixed? Dont need any more help?
BitcoinMoxy
Full Member
***
Offline Offline

Activity: 120
Merit: 100


BitcoinMoxy.com


View Profile WWW
May 29, 2013, 04:19:35 PM
 #10

So your problems completly fixed? Dont need any more help?

I'll keep you updated soon. (I take it that's an offer for help.)





BitcoinMoxy.com - Your Gateway into the World of Bitcoin for Newcomers, Day Traders, Advertisers.
Service updates: https://bitcointalk.org/index.php?topic=254631.0
BitcoinMoxy
Full Member
***
Offline Offline

Activity: 120
Merit: 100


BitcoinMoxy.com


View Profile WWW
June 07, 2013, 06:23:04 PM
 #11

Streamlined our QR Code generator some more by replacing the textarea input field with a proper input field and ensured cross-browser compatibility.

Figured this one out all by myself (I'm so proud...)


The input field is autofocused, so loading the page and hitting CTRL-V and ENTER will now generate the QR-code just like snapping your fingers.

Note: This works for any altcoins, too!


BitcoinMoxy.com


BitcoinMoxy.com - Your Gateway into the World of Bitcoin for Newcomers, Day Traders, Advertisers.
Service updates: https://bitcointalk.org/index.php?topic=254631.0
rolloffacliffpleaseanddie
Newbie
*
Offline Offline

Activity: 14
Merit: 0


View Profile
June 07, 2013, 06:31:20 PM
 #12

cool glad you got it fixed!
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!