lundi 13 août 2018

Javascript match and test returning null to DOI Regex expression

I have been trying to find a way to recognize DOI on an input form to trigger a specific search. I found a DOI regular expression here and when I use it with Match or Test I got 'NULL' and Error as result

function checkDOI(string){
        //Redundant. I know 
        var testKey = String(string);
        var DOIpattern = '\b(10[.][0-9]{4,}(?:[.][0-9]+)*/(?:(?!["&\'<>])\S)+)\b';

        var found = DOIpattern.test(testKey);
        console.log("found", found + " DOI "+ testKey);
        return found
      }
checkDOI("10.1016.12.31/nature.S0735-1097(98)2000/12/31/34:7-7")

I got this error DOIpattern.test is not a function

Then if I change the found.test for MATCH var found = DOIpattern.match(testKey);

The result is NULL

Does anybody can tell me what I am doing wrong?

Thank in advance!

Aucun commentaire:

Enregistrer un commentaire