Click here to Skip to main content
16,004,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I want to check whether a string is SQL Keyword or not from JAVASCRIPT.
Googled a lot. But could not be able to find a suitable solution
Plz. help.
Posted
Updated 2-Dec-14 19:45pm
v2

var str = "select * from employee"; 
str = str.toLowerCase()
var res = str.match(/select/ltrim/rtirm/where/group by/from/asc); 

The result of res will be an array with the values:

select,from etc.
 
Share this answer
 
Simple solution is to store all the keywords in a JavaScript Array.

Check if the string is present in the Array or not. That's it.
 
Share this answer
 
Comments
Maciej Los 3-Dec-14 1:52am    
+5
Thanks Maciej. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900