Page 2 of 2

How do I parse data from a QR Barcode scan and then do a DB write?

Posted: Fri Oct 18, 2013 4:49 pm
by Maryna Brodina

Hello! prereturn value.match(/FN:(.+)TEL/)[1];/pre should be working
Please check if you have what you expect in value variable. Add before this line prealert(value);/pre and see what you have in alert.


How do I parse data from a QR Barcode scan and then do a DB write?

Posted: Sat Oct 19, 2013 5:27 am
by Christopher Herold

Hi Maryna!

When I do the alert(value) the alert that pops up does contain the content as follows:

BEGIN:VCARD VERSION:2.1 FN:Chris Herold TEL;work:888-919-0919 EMAIL;INTERNET;work:a href="mailto:msacl@gmail.com" rel="nofollow"msacl@gmail.com/a END:VCARD

So the data is in value, but for some reason value isn't being parsed correctly by the javascript code.

Do you think it could be that there are semicolons in the content?

I am not sure what to try next.

What do you think?


How do I parse data from a QR Barcode scan and then do a DB write?

Posted: Sat Oct 19, 2013 3:24 pm
by Christopher Herold

Any thoughts?


How do I parse data from a QR Barcode scan and then do a DB write?

Posted: Sat Oct 19, 2013 4:07 pm
by Illya Stepanov

Sorry no news for now, we'll update when we'll have more information.


How do I parse data from a QR Barcode scan and then do a DB write?

Posted: Sat Oct 19, 2013 10:27 pm
by Igor

Hello,

You can try to add value alerts before and after "match" function. Use next code:
pre
var a= value;
alert(a);
b=a.match(/FN:(.+?)TEL/)[1];
alert(b);
return b;
/pre


How do I parse data from a QR Barcode scan and then do a DB write?

Posted: Tue Oct 22, 2013 1:04 am
by Christopher Herold

So we've got a tricky one here.

codevar a = "BEGIN:VCARD VERSION:2.1 FN:Chris Herold TEL;work:888-919-0919 EMAIL;INTERNET;work:msacl@gmail.com END:VCARD&quot
alert(value);
b = a.match(/FN:(.+?)TEL/)[1];
alert(b);
return b;/code

The code above will work fine with code var a /code explicitly defined.
The alert to test the content of value codealert(value);/code pops up an alert with the expected content from the barcode scan (which is identical to what is in var a).
The variable codeb/code returns the expected output for the match: "Chris Herold" when the match target is codea/code.

However, when I change the match target from codea/code to codevalue/code, as done below ... nothing works, except the initial alert outputing the content that is identical to the content of var a.
alert b ends up with no value, and hence no alert.

codevar a = "BEGIN:VCARD VERSION:2.1 FN:Chris Herold TEL;work:888-919-0919 EMAIL;INTERNET;work:msacl@gmail.com END:VCARD&quot
alert(value);
b = value.match(/FN:(.+?)TEL/)[1];
alert(b);
return b;/code

How can this be happening? There must be some way that I need to encase 'value' to have it render properly, perhaps because the content it contains has semicolons????


How do I parse data from a QR Barcode scan and then do a DB write?

Posted: Tue Oct 22, 2013 6:04 am
by Christopher Herold

I figured it out. The data that was being sent in on the VCARD included hidden new line characters ... \n.

It appears that the newline characters MUST BE REMOVED from the contents of "value" for the match to run successfully.

The first line of code below removes the newline characters and replaces them with nothing, using empty quotes. The second line performs the match and returns the value for use in the app.

code
var value = value.replace(/\n/g,"");

return value.match(/FN:(.+?)TEL/)[1];
/code

Thanks for everyone's help on this. You all got me up to speed on remedial javascript and I just needed to look closely at the content of value until I figured it out. Thanks team Appery!


How do I parse data from a QR Barcode scan and then do a DB write?

Posted: Tue Oct 22, 2013 7:37 am
by Maryna Brodina

Hello! Glad it's working now! Thank you for update!