且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从Javascript验证字符串是否是SQl关键字

更新时间:2023-02-06 14:11:27

简单的解决方案是将所有关键字存储在 JavaScript 数组中>。



检查字符串是否存在于数组中。就是这样。
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.


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.