# HG changeset patch # User Pascal Bellard # Date 1359369996 -3600 # Node ID eac3b3cbb737bf8a6eebd4594f8e14b2670a5e59 # Parent e4bf1581a71bf0f383fa3995a2e6043cc8d27567 lib/functions.js: desc should not be executable (again) diff -r e4bf1581a71b -r eac3b3cbb737 web/lib/functions.js --- a/web/lib/functions.js Mon Jan 28 09:34:12 2013 +0100 +++ b/web/lib/functions.js Mon Jan 28 11:46:36 2013 +0100 @@ -1,30 +1,33 @@ // SliTaz Pizza Javascript functions. // +function charactersOK(field, name) { + var str = "`!@#$%^&*()+=[]\\\';,./{}|\":<>?"; + if(document.forms["pizza"][field].value == "") { + alert("Please enter"+name); + document.forms["pizza"][field].focus(); + return false; + } + for (var i = 0; i < document.forms["pizza"][field].value.length; i++) { + if (str.indexOf(document.forms["pizza"][field].value.charAt(i)) != -1) { + alert ("Invalid "+name+".\n Please remove special characters."); + document.forms["pizza"][field].focus(); + return false; + } + } + return true; +} + // Check form to avoid empty values and bad email. function checkForm() { - if(document.forms["pizza"]["flavor"].value == "") - { - alert("Please enter SliTaz pizza flavor name"); - document.forms["pizza"]["flavor"].focus(); - return false; - } else { - var str = "!@#$%^&*()+=[]\\\';,./{}|\":<>?"; - for (var i = 0; i < document.forms["pizza"]["flavor"].value.length; i++) { - if (str.indexOf(document.forms["pizza"]["flavor"].value.charAt(i)) != -1) - { - alert ("Invalid Flavor name.\n Please remove special characters."); - document.forms["pizza"]["desc"].focus(); - return false; - } - } - } - if(document.forms["pizza"]["desc"].value == "") - { - alert("Please fill in the flavor description"); - document.forms["pizza"]["desc"].focus(); - return false; - } + if (!charactersOK("flavor", "pizza flavor name", + "`!@#$%^&*()+=[]\\\';,./{}|\":<>?")) + return false; + if (!charactersOK("desc", "flavor description", + "`!@#$%^&*()+=[]\\\';,./{}|\":<>?")) + return false; + if (!charactersOK("mail", "email address", "$`\\")) + return false; var x=document.forms["pizza"]["mail"].value; var atpos=x.indexOf("@"); var dotpos=x.lastIndexOf(".");