如何从Javascript验证字符串是否是SQl关键字 [英] How to validate whether a string is SQl Keyword or not from Javascript
本文介绍了如何从Javascript验证字符串是否是SQl关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从JAVASCRIPT检查字符串是否是SQL关键字。
Google搜索了很多。但无法找到合适的解决方案
Plz。帮助。
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.
推荐答案
简单的解决方案是将所有关键字存储在 JavaScript数组
。
检查字符串是否存在于数组
中。就是这样。
Simple solution is to store all the keywords in a JavaScriptArray
.
Check if the string is present in theArray
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.
这篇关于如何从Javascript验证字符串是否是SQl关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文