string starts with x or y
Posted: Thu Jul 22, 2010 11:24 am
I'm trying to set up some javascript to check a MySQL query before it gets processed. It needs to check that the query starts with either 'SELECT' or 'SHOW', as these are the only two actions permitted. I also want it to check that there is only one ';' and that it is at the end.
I was doing fine, until I tried to add in the OR (SELECT OR SHOW) part. what I have thus far is:
what can I do to pick up the two options?
I was doing fine, until I tried to add in the OR (SELECT OR SHOW) part. what I have thus far is:
Code: Select all
function sqlcheck(str) {
var se1="SELECT"
var se2="SHOW"
var sc=";"
var lse1=str.indexOf(se1)
var lse2=str.indexOf(se2)
var lstr=str.length
var lsc=str.indexOf(sc)
if ((str.indexOf(se1)!=0)||(str.indexOf(se2)!=0)){
alert("Start with SELECT or SHOW")
return false
}
if (str.indexOf(sc)!=str.length-1){
alert("end with a ;")
return false
}
return true
}
function ValidateForm(){
document.MySQL_Query.query.value = document.MySQL_Query.query.value.toUpperCase();
var query=document.MySQL_Query.query
if ((query.value==null)||(query.value=="")){
alert("Please Enter a MySQL Query")
qyery.focus()
return false
}
if (sqlcheck(query.value)==false){
query.value=""
query.focus()
return false
}
return true
}