« Remove from version control but keep the file | Main | IE 7 Zero Length Regex Matches »
June 13, 2011
Detect curly quotes with JavaScript
function check_quotes(){ var s = ''; var regex = /\W/g; var m = null; var text = null; var code = null; ['asset_name','body','summary'].each(function(da_id){ text = document.getElementById(da_id).value; m = regex.exec(text); if(da_id == 'asset_name'){ da_id = 'title'; } var count = 0; while(m){ code = m[0].charCodeAt(0); if(code > 8200){ s = s + "\n<li> Found " + m + " in " + da_id.split('_').join(' ') + " text</li>"; count++; } count++; m = regex.exec(text); } }); if(s != ''){ poppy('Illegal characters found in your title or description:<br/><br/><ul>' + s + '</ul><br/>Delete and then re-type quotes and long dashes in the editor above before proceeding. Please try and avoid cutting and pasting from Word.'); return true; } return false; }
Tags: Curly quotes , JavaScript
Posted by pj at June 13, 2011 04:23 PM