// pattern_test.js // Help out HTML like pattern_test.htm // RJM Programming - February, 2021 // To suit validation on an input type=text for a comma separated list of positive integers var ejajs=location.search.split("theelementid=")[1] ? decodeURIComponent(location.search.split("theelementid=")[1].split('&')[0]).replace(/\;\ /g, '; ' + String.fromCharCode(10)) : ""; var ejpattern=location.search.split("pattern=")[1] ? decodeURIComponent(location.search.split("pattern=")[1].split('&')[0]).replace(/\;\ /g, '; ' + String.fromCharCode(10)) : ""; if (ejajs.trim() == '') { if (document.head.innerHTML.indexOf('pattern_test.js?theelementid=') != -1) { if (ejpattern.trim() == '' && document.head.innerHTML.indexOf('&pattern=') != -1) { ejpattern=decodeURIComponent(document.head.innerHTML.split('&pattern=')[1].split('&')[0].split("'")[0].split('"')[0].split('>')[0]); } ejajs=document.head.innerHTML.split("pattern_test.js?theelementid=")[1] ? decodeURIComponent(document.head.innerHTML.split("pattern_test.js?theelementid=")[1].split('&')[0].split('>')[0].split('"')[0].split("'")[0]).replace(/\;\ /g, '; ' + String.fromCharCode(10)) : ""; } else if (document.body.innerHTML.indexOf('?theelementid=') != -1) { if (ejpattern.trim() == '' && document.body.innerHTML.indexOf('&pattern=') != -1) { ejpattern=decodeURIComponent(document.body.innerHTML.split('&pattern=')[1].split('&')[0].split("'")[0].split('"')[0].split('>')[0]); } ejajs=document.body.innerHTML.split("?theelementid=")[1] ? decodeURIComponent(document.body.innerHTML.split("?theelementid=")[1].split('&')[0].split('>')[0].split('"')[0].split("'")[0]).replace(/\;\ /g, '; ' + String.fromCharCode(10)) : ""; } else if (document.body.innerHTML.indexOf('&theelementid=') != -1) { if (ejpattern.trim() == '' && document.body.innerHTML.indexOf('?pattern=') != -1) { ejpattern=decodeURIComponent(document.body.innerHTML.split('?pattern=')[1].split('&')[0].split("'")[0].split('"')[0].split('>')[0]); } ejajs=document.body.innerHTML.split("&theelementid=")[1] ? decodeURIComponent(document.body.innerHTML.split("&theelementid=")[1].split('&')[0].split('>')[0].split('"')[0].split("'")[0]).replace(/\;\ /g, '; ' + String.fromCharCode(10)) : ""; } } if (ejpattern == '') { ejpattern='[0-9,]*'; } function ats() { var thestyle='', thescript=''; if (ejajs.trim() != '') { thestyle+=String.fromCharCode(10) + " " + String.fromCharCode(10); //alert(thestyle); document.body.innerHTML+=thestyle; var ejtag = document.createElement('script'); ejtag.type='text/javascript'; thescript+=String.fromCharCode(10) + " var ejajs='" + ejajs + "'; "; thescript+=String.fromCharCode(10) + " var ejpattern='" + ejpattern + "'; "; thescript+=String.fromCharCode(10) + " var ejprev=''; "; thescript+=String.fromCharCode(10) + " var ejretval=''; "; thescript+=String.fromCharCode(10) + " var ejvalidilist=''; "; thescript+=String.fromCharCode(10) + " "; thescript+=String.fromCharCode(10) + " function ejpostonl() { "; thescript+=String.fromCharCode(10) + " document.getElementById('" + ejajs + "').setCustomValidity(''); "; thescript+=String.fromCharCode(10) + " } "; thescript+=String.fromCharCode(10) + " "; thescript+=String.fromCharCode(10) + " function ejreval() { "; thescript+=String.fromCharCode(10) + " document.getElementById('" + ejajs + "').value=ejprev; "; thescript+=String.fromCharCode(10) + " } "; thescript+=String.fromCharCode(10) + " "; thescript+=String.fromCharCode(10) + " function ejonl() { "; thescript+=String.fromCharCode(10) + " if (('' + location.hash) != '') { "; thescript+=String.fromCharCode(10) + " document.getElementById('" + ejajs + "').title='Regarding your invalid entry of ' + decodeURIComponent('' + location.hash).replace('#','') + ', ' + ('' + document.getElementById('" + ejajs + "').placeholder).substring(0,1).toLowerCase() + (document.getElementById('" + ejajs + "').placeholder + ' ').substring(1); "; thescript+=String.fromCharCode(10) + " } "; thescript+=String.fromCharCode(10) + " ejprev = location.search.split('" + ejajs + "=')[1] ? decodeURIComponent(location.search.split('" + ejajs + "=')[1].split('&')[0]) : ''; "; thescript+=String.fromCharCode(10) + " if (document.getElementById('" + ejajs + "').outerHTML.indexOf(' pattern=') == -1) { document.getElementById('" + ejajs + "').pattern=ejpattern; } "; thescript+=String.fromCharCode(10) + " if (document.getElementById('" + ejajs + "').outerHTML.indexOf(' placeholder=') == -1 && ('' + document.getElementById('" + ejajs + "').title) != '') { document.getElementById('" + ejajs + "').placeholder=document.getElementById('" + ejajs + "').title; } "; thescript+=String.fromCharCode(10) + " else if (document.getElementById('" + ejajs + "').outerHTML.indexOf(' placeholder=') != -1 && ('' + document.getElementById('" + ejajs + "').title) == '') { document.getElementById('" + ejajs + "').title=document.getElementById('" + ejajs + "').placeholder; } "; thescript+=String.fromCharCode(10) + " else { document.getElementById('" + ejajs + "').placeholder='Please enter a comma separated positive integer list (where red dashed border flags invalid entry)'; document.getElementById('" + ejajs + "').title=document.getElementById('" + ejajs + "').placeholder; } "; thescript+=String.fromCharCode(10) + " document.getElementById('" + ejajs + "').title = location.search.split('" + ejajs + "=')[1] ? ('Thanks for entering the valid " + '"' + "' + decodeURIComponent(location.search.split('" + ejajs + "=')[1].split('&')[0]) + '" + '"' + "').replace('Thanks for entering the valid " + '""' + "', document.getElementById('" + ejajs + "').placeholder) : document.getElementById('" + ejajs + "').placeholder; "; thescript+=String.fromCharCode(10) + " var theforms=document.getElementsByTagName('form'), thefid='myform'; "; thescript+=String.fromCharCode(10) + " if (ejprev != '') { setTimeout(ejreval,3000); } "; thescript+=String.fromCharCode(10) + " if (theforms.length > 0) { for (var theformslength=1; theformslength<=theforms.length; theformslength++) { if (theforms[eval(-1 + theformslength)].outerHTML.indexOf(' id=" + '"' + ejajs + '"' + "') != -1) { "; thescript+=String.fromCharCode(10) + " if (document.getElementById('" + ejajs + "').outerHTML.indexOf(' name=') == -1 && document.getElementById('" + ejajs + "').outerHTML.indexOf(' id=') != -1) { document.getElementById('" + ejajs + "').name=document.getElementById('" + ejajs + "').id; } "; thescript+=String.fromCharCode(10) + " if (theforms[eval(-1 + theformslength)].outerHTML.indexOf(' id=') == -1) { "; thescript+=String.fromCharCode(10) + " theforms[eval(-1 + theformslength)].id='myform'; "; thescript+=String.fromCharCode(10) + " } else { "; thescript+=String.fromCharCode(10) + " thefid=theforms[eval(-1 + theformslength)].id; "; thescript+=String.fromCharCode(10) + " } "; thescript+=String.fromCharCode(10) + " if (theforms[eval(-1 + theformslength)].outerHTML.indexOf(' action=') == -1) { "; thescript+=String.fromCharCode(10) + " theforms[eval(-1 + theformslength)].action=document.URL.split('#')[0].split('?')[0]; "; thescript+=String.fromCharCode(10) + " } "; thescript+=String.fromCharCode(10) + " if (theforms[eval(-1 + theformslength)].outerHTML.indexOf(' method=') == -1) { "; thescript+=String.fromCharCode(10) + " theforms[eval(-1 + theformslength)].method='GET'; "; thescript+=String.fromCharCode(10) + " } "; thescript+=String.fromCharCode(10) + " if (theforms[eval(-1 + theformslength)].outerHTML.indexOf(' onsubmit=') == -1) { console.log(67); "; thescript+=String.fromCharCode(10) + " theforms[eval(-1 + theformslength)].onsubmit = function(event) { return ejosb(event.target); }; "; thescript+=String.fromCharCode(10) + " } else { console.log(theforms[eval(-1 + theformslength)].outerHTML); } "; thescript+=String.fromCharCode(10) + " } } } "; thescript+=String.fromCharCode(10) + " "; thescript+=String.fromCharCode(10) + " document.getElementById('" + ejajs + "').oninvalid = function(event) { "; thescript+=String.fromCharCode(10) + " ejretval=event.target.value; "; thescript+=String.fromCharCode(10) + " if (event.target.title.indexOf(', ') != -1) { "; thescript+=String.fromCharCode(10) + " event.target.title=document.event.target.placeholder; "; thescript+=String.fromCharCode(10) + " } "; thescript+=String.fromCharCode(10) + " event.target.setCustomValidity('Regarding your invalid entry of " + '"' + "' + ejretval + '" + '"' + ", ' + ('' + event.target.title).substring(0,1).toLowerCase() + (event.target.title + ' ').substring(1)); "; thescript+=String.fromCharCode(10) + " event.target.title=('Regarding your invalid entry of " + '"' + "' + ejretval + '" + '"' + ", ' + ('' + event.target.title).substring(0,1).toLowerCase() + (event.target.title + ' ').substring(1)); "; thescript+=String.fromCharCode(10) + " event.target.value=''; "; thescript+=String.fromCharCode(10) + " setTimeout(ejpostonl, 5000); "; thescript+=String.fromCharCode(10) + " }; "; thescript+=String.fromCharCode(10) + " } "; thescript+=String.fromCharCode(10) + " "; thescript+=String.fromCharCode(10) + " function ejosb(fois) { console.log(0); "; thescript+=String.fromCharCode(10) + " if (ejretval != '') { console.log(1); "; thescript+=String.fromCharCode(10) + " fois.action='#' + decodeURIComponent(ejretval); "; thescript+=String.fromCharCode(10) + " if (document.getElementById('" + ejajs + "').title.indexOf(', ') != -1) { "; thescript+=String.fromCharCode(10) + " document.getElementById('" + ejajs + "').title=document.getElementById('" + ejajs + "').placeholder; "; thescript+=String.fromCharCode(10) + " } "; thescript+=String.fromCharCode(10) + " ejretval=''; "; thescript+=String.fromCharCode(10) + " return false; "; thescript+=String.fromCharCode(10) + " } else { console.log(2); "; thescript+=String.fromCharCode(10) + " document.getElementById('" + ejajs + "').setCustomValidity(''); "; thescript+=String.fromCharCode(10) + " ejvalidilist=document.getElementById('" + ejajs + "').value; "; thescript+=String.fromCharCode(10) + " } "; thescript+=String.fromCharCode(10) + " return true; "; thescript+=String.fromCharCode(10) + " } "; thescript+=String.fromCharCode(10) + " "; thescript+=String.fromCharCode(10) + " if (ejajs.trim() != '') { setTimeout(ejonl,2000); } " + String.fromCharCode(10); console.log(thescript); ejtag.src='data:text/javascript;base64,' + btoa(thescript); //alert(thescript.slice(-450)); document.head.appendChild(ejtag); ejajs=''; } } setTimeout(ats, 3000);